Python persistent dictionary?

Python persistent dictionary?

I just had an interesting thing happen in Python while working on rwrapper that I haven’t come across yet, it really had me baffled and I’m still not sure why it does it yet. I’ll do some research later and try update this post with an answer. The code below will produce a consistent dictionary in the parent class, so any new child class created will contain the dictionary attributes from the previous instance.

With this code when you instantiate ChildB().mydict() the results will contain field1 from the instance of ChildA


The solution was to instantiate the dictionary during __init__



About David Parlevliet

Dave is long time developer with a passion toward teaching. He divides his time between his wife, her cat and his projects. He recently started using twitter so make sure to follow him!