Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3335598
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:02:12+00:00 2026-05-18T00:02:12+00:00

I have a python question that I’m sure is pretty simple – please feel

  • 0

I have a python question that I’m sure is pretty simple – please feel free to disabuse me of any sort of bad practice while you’re at it. I have the following code:

class User(dict,BaseDBI):
    def __init__(self,uid=None,username=None):
        self['uid']=str(uuid())     
        if uid == None and username is not None:            
            uid_struct = self.Get('data/username.kch',username)         
            if uid_struct is not None:
                self = self.Get('data/user.kch',uid_struct['uid'])

As you can tell this User is simply an extended dict object. It also accesses a few simple Get and Set methods on a couple of Kyoto Cabinet db files. I put in some print statements to trace through what’s going on and everything is being set properly, but when I create a User object (e.g.):

user = User(username='someusername')

and then print user I only have a new dict object that has the brand new uid generated by the first line under __init__

Thanks for any wisdom!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:02:13+00:00Added an answer on May 18, 2026 at 12:02 am

    python variables are references. when you assign to self, you are replacing that reference but not altering the object which is returned by __init__.

    The easiest thing may be to simply use the dict.update method to copy all key/value pairs into self. This should ‘just work’ since you’re already inheriting from dict.

    Inheritance is only appropriate for a relationship like A is a B. You indicate that a User is a dict, that’s fine, but I doubt that a User is a BaseDBI. It’s more likely that you want a User to have a database, in which case composition is more appropriate. This probably seems nit-picky, but will prevent you from making bizarre and obscene systems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have another newbie Python question. I have the following piece of code that
A question that seems to have quite a few options for Python, but none
I have a simple question about Python: I have another Python script listening on
I have a python script that is constantly grabbing data from Twitter and writing
I have a quick Hadoop Streaming question. If I'm using Python streaming and I
This may not really be a Python related question, but pertains to language encoding
I have new to python and django I am creating poll application and in
I have a Python project with following directory structure: /(some files) /model/(python files) /tools/(more
(I am working interactively with a WordprocessingDocument object in IronPython using the OpenXML SDK,
This is a problem I've been racking my brains on for a long time,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.