Help and optimization hints, anyone?

Kim Petersen kim at lignus.dk
Fri Jan 23 17:39:31 CET 2004


Den Fri, 23 Jan 2004 16:20:37 +0000. skrev John J. Lee:

> Kim Petersen <kim at lignus.dk> writes:
>> Den Fri, 23 Jan 2004 12:32:04 +0000. skrev John J. Lee:
> [...]
>> > dict is also a bad name -- this is the name of the builtin dictionary
>> > type, which you've just clobbered (in the local scope).
>> 
>> Hmmm - isn't it called __dict__ ?
> 
> No, __dict__ is an attribute of Python objects.  It's the dictionary
> in which most Python objects keep their data:

ah - the class dict() - yeah i can see that (i didn't notice since
i hardly ever call dict() directly but do it indirectly via {}. Sure
i've clobbered that internally in this class and derived (will change)

>> > Haven't read much further, but it looks like you might be better off
>> > using attribute access rather than indexing.  In 2.2, use properties.
>> > Earlier, use __setattr__ / __getattr__ (make sure you read the docs).
>> 
>> this migrated from a regular dict which i had to drop because its
>> not hashable as mentioned earlier - next step __(get|set)attr__.
> 
> dicts are deliberately not hashable, because they're mutable.  Are you
> sure you want a dict as a dictionary key (assuming that's what you're
> doing)?

I had the columns,rows and cells as simply dicts in the beginning,
but that made self.cells[(row,column)] impossible - so i converted
to classes instead (which works just as well). And migrated func-
tionality to the classes. [this is also the reason for the attributes
being access as dict].
> 
> 
> John

-- 
Privat  ==========================  Kim Petersen  ====================  Arbejde
Email kim at vindinggaard.dk  =====  Jens Grøns Vej 11  =====  Email kim at lignus.dk
Tlf +45 75 83 15 50  ==============  7100 Vejle  =========  Tlf +45 75 83 15 51
Fax +45 75 83 15 62  =============  DK - Danmark  ========  Fax +45 75 83 15 62




More information about the Python-list mailing list