> Though I solved the problem by making database an instance variable,
> there's one thing I'm curious about. If I 'overwrite' a class variable
> with an instance one (as I did originally), is the class variable
> recoverable?
Yes, you can always access the class version by using the class
as th
> If I 'overwrite' a class variable
> with an instance one (as I did originally), is the class variable
> recoverable? Will objects created later have the class or the instance
> variable?
yes, but you need to access it with the class name: Grammars.database
the other (uglier) alternative is to
Though I solved the problem by making database an instance variable,
there's one thing I'm curious about. If I 'overwrite' a class variable
with an instance one (as I did originally), is the class variable
recoverable? Will objects created later have the class or the instance
variable?
Basu
--
T
> > Then database will be shared by all instances of Grammars
>
> No, the assignment
> gram.database = {}
> will always (at least absent any extra magic) create an instance attribute.
Ah yes, silly me. The assignment creates a new instance variable.
If you were only reading gram.database it woul
On 27/06/2008, Kent Johnson <[EMAIL PROTECTED]> wrote:
> No, the assignment
> gram.database = {}
> will always (at least absent any extra magic) create an instance attribute.
I think this is the OP's workaround. Quoting:
"Shrutarshi Basu":
> I have to manually clear gram.database because
> ot
It turns out that Alan's catch of the instance vs class variables was
right. database was declared in the class body, rather than in the
__init__. Doing gram.database = {}, may have replaced it.. But I've
changed the Grammars class to have the proper instance variables.
Apparently my teammates and
On Thu, Jun 26, 2008 at 6:30 PM, Alan Gauld <[EMAIL PROTECTED]> wrote:
>
> "Shrutarshi Basu" <[EMAIL PROTECTED]> wrote
>
>> def parse_display(self ):
>>
>> try:
>> gram = Grammars(10, 10, self.pc_map, self.hard_rules)
>> gram.database = {}
>
> How is gram.database defined? I
On Thu, Jun 26, 2008 at 5:55 PM, Shrutarshi Basu
<[EMAIL PROTECTED]> wrote:
> Here's the relevant function:
Which is the dict that is causing trouble?
Kent
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On Jun 26, 2008, at 2:59 PM, Shrutarshi Basu wrote:
self.modules.append(DisplayModule(self.img_map,
(self.xOrigin, self.yOrigin), self.rows, self.columns, gram,
self.type))
...
As you can see, not only do I delete gram, I also blank out everything
that should be cleared. I have to ma
"Shrutarshi Basu" <[EMAIL PROTECTED]> wrote
def parse_display(self ):
try:
gram = Grammars(10, 10, self.pc_map, self.hard_rules)
gram.database = {}
How is gram.database defined? Is it an instance attribue or
a class attribute? If you have
class Grammars:
data
Here's the relevant function:
def parse_display(self ):
try:
gram = Grammars(10, 10, self.pc_map, self.hard_rules)
gram.database = {}
for key, list in self.grammars.iteritems():
gram.addGram(key, list[0], list[1])
self.modules
On Thu, Jun 26, 2008 at 4:25 PM, Shrutarshi Basu
<[EMAIL PROTECTED]> wrote:
> At least that's what we want to do. This whole thing is inside a
> function. However, when we call that function again to create another
> Gen object, the new object seems to retain the dbase dictionary from
> the last t
I've been writing code where we have a class that does some basic
ordering and packaging of data we send in its constructor. Let's call
it Gen. At a particular point in our code we create an object:
genObject = Gen( someInt, someInt, aDict, aList)
genObject has a dictionary called dbase, which us
13 matches
Mail list logo