[ python-Bugs-1012249 ] dictionary referencing error

SourceForge.net noreply at sourceforge.net
Thu Aug 19 18:00:52 CEST 2004


Bugs item #1012249, was opened at 2004-08-19 09:57
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1012249&group_id=5470

Category: Parser/Compiler
Group: Python 2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: AMIT Consulting LLC (ckbcouture)
Assigned to: Nobody/Anonymous (nobody)
Summary: dictionary referencing error

Initial Comment:
When I write a class as such:


class MyObject:

   myDict = {}

   ...


Each new instance refers to the SAME dictionary, not a 
newly minted one.  However, this does not hold true for 
other data types.

This has forced me to place dictionary declarations in 
the __init__ method to ensure uniqueness.

Unless this is intended for some obscure reason, it 
should be fixed.

Thanks,
Cameron




----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-08-19 11:00

Message:
Logged In: YES 
user_id=80475

That is the intended behavior.  Attribute definitions inside
the class definition but outside the method definitions are
essentially class variables.  They are useful because each
instance does not need to have its own copy.  For cases
where an instance needs its own copy, your solution using
__init__ was the right thing to do.

In time, this will be obvious and all will feel as right as
rain.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1012249&group_id=5470


More information about the Python-bugs-list mailing list