<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
That worked. Thank you for the explanation. <br><br>I was trying to take a list of these objects and insert it as a part of a mongo document using the pymongo package. <br><br>But based on what your input and little more reading up, I can use the "__dict__" method to accomplish the same.<br><br>Thanks again.<br><br>- Mukund<br><br><br><div>&gt; Date: Thu, 22 Sep 2011 10:58:09 +1000<br>&gt; From: steve@pearwood.info<br>&gt; To: tutor@python.org<br>&gt; Subject: Re: [Tutor] List of Classes with a dictionary within the Class.<br>&gt; <br>&gt; Mukund Chavan wrote:<br>&gt; &gt; Hi,<br>&gt; &gt; <br>&gt; &gt; I was trying to get a list of Class Objects. <br>&gt; &gt; The Class itself has string fields and a dictionary that is initialized as a part of the "__init__"<br>&gt; <br>&gt; No it doesn't. It has a dictionary that is initialised *once*, when the <br>&gt; class is defined. From that point on, every instance just modifies the <br>&gt; same shared dictionary:<br>&gt; <br>&gt; &gt; class Person(object):<br>&gt; &gt;    """__init__() functions as the class constructor"""<br>&gt; &gt;    personAttrs={"'num1":"","num1":""}<br>&gt; <br>&gt; This is a "class attribute", stored in the class itself, and shared <br>&gt; between all instances.<br>&gt; <br>&gt; <br>&gt; &gt;    def __init__(self, name=None, job=None, quote=None, num1=None, num2=None):<br>&gt; &gt;       self.name = name<br>&gt; &gt;       self.job = job<br>&gt; &gt;       self.quote = quote<br>&gt; &gt;       self.personAttrs["num1"]=num1<br>&gt; &gt;       self.personAttrs["num2"]=num2<br>&gt; <br>&gt; This merely modifies the existing class attribute. You want something <br>&gt; like this instead:<br>&gt; <br>&gt; class Person(object):<br>&gt;      def __init__(self, name=None, job=None, quote=None,<br>&gt;                   num1=None, num2=None<br>&gt;                  ):<br>&gt;          self.name = name<br>&gt;          self.job = job<br>&gt;          self.quote = quote<br>&gt;          self.personAttrs = {'num1': num1, 'num2': num2}<br>&gt; <br>&gt; This creates a new dictionary for each Person instance.<br>&gt; <br>&gt; But why are you doing it that way? Each Person instance *already* has <br>&gt; its own instance dictionary for storing attributes. You don't need to <br>&gt; manage it yourself -- just use ordinary attributes, exactly as you do <br>&gt; for name, job, and quote.<br>&gt; <br>&gt; class Person(object):<br>&gt;      def __init__(self, name=None, job=None, quote=None,<br>&gt;                   num1=None, num2=None<br>&gt;                  ):<br>&gt;          self.name = name<br>&gt;          self.job = job<br>&gt;          self.quote = quote<br>&gt;          self.num1 = num1<br>&gt;          self.num2 = num2<br>&gt; <br>&gt; <br>&gt; <br>&gt; -- <br>&gt; Steven<br>&gt; _______________________________________________<br>&gt; Tutor maillist  -  Tutor@python.org<br>&gt; To unsubscribe or change subscription options:<br>&gt; http://mail.python.org/mailman/listinfo/tutor<br></div>                                               </div></body>
</html>