newbie: class and __dict__ variable.

Discussion in 'Python' started by mafeusek@gmail.com, Sep 19, 2010.

  1. Guest

    Hallo Group Members. From time to time I see in python code following
    notation that (as I believe) extends namespace of MyClass.
    class MyClass:
    def __init__(self):
    self.__dict__["maci"]=45

    myCl2 = MyClass2()
    print myCl2.maci


    I am guessing that there must be some difference between the one above
    and the one below, because otherwise no one would probably use the one
    above. Do YOu know that difference?

    class MyClass2:
    def __init__(self):
    self.maci=45


    myCl = MyClass()
    print myCl.maci

    best regards,
    Pawel
     
    , Sep 19, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Derek Fountain

    When is a __dict__ not a __dict__?

    Derek Fountain, Apr 21, 2004, in forum: Python
    Replies:
    1
    Views:
    334
    John Roth
    Apr 21, 2004
  2. Tamas Nepusz
    Replies:
    0
    Views:
    516
    Tamas Nepusz
    May 9, 2006
  3. Zack
    Replies:
    9
    Views:
    267
    Arnaud Delobelle
    Feb 17, 2008
  4. Replies:
    1
    Views:
    275
    Diez B. Roggisch
    May 19, 2008
  5. Terry Reedy
    Replies:
    4
    Views:
    322
    Terry Reedy
    Sep 20, 2010
Loading...

Share This Page