[Tutor] I Give Up. - Follow up post

Alan Gauld alan.gauld at freenet.co.uk
Thu Jul 6 00:25:29 CEST 2006


> Comes from wanting to minimize how much stuff I have loaded into 
> memory, and my impression is, a dictionary of 2 elements (name:value 
> pairs)
> takes up more space in memory than two single variables (name points 
> to value in memory),

Dangerous assumption since Python ultimately uses dictionaries for 
*all*
its variables, its just that some of them are somewhat hidden from 
view...
So evern if you declare

foo = 42

it gets turned into

local_vars[foo'] = 42

or something similar....

So by declaring your own dictionary the only overhead is the extra
dictionary entry to point at your explicit doictionary.

Dictionaries in Python are pretty efficient since they are
the bedrock of the interpreter.

HTH,

Alan G. 




More information about the Tutor mailing list