On 05/17/11 12:30 PM, Keith Mitchell wrote:
On 05/17/11 12:15 PM, Shawn Walker wrote:
On 05/17/11 11:16 AM, Keith Mitchell wrote:
On 05/17/11 11:12 AM, William Schumann wrote:
Keith,
I have one preliminary question:
On 05/16/11 07:29 PM, Keith Mitchell wrote:
...
ns_info.py:
...
225: This dict should be statically defined.
265-276: Statically define this somewhere.
What you mean by 'statically', and why?
I guess "global" would be more precise. Or rather, at the module level.
As written, every time the function is called, the dictionary is
reconstructed; and since the objects seemed to be only read-from, never
written-to, it seemed like they should be defined at the module level,
instead of as locals.
That's not true. Lists, dictionaries, tuples, etc. that can be
completely interpreted at compile time will be the same object every
time:
#!/usr/bin/python2.6
def test():
propdict = { 'key': 'value' }
print "propdict id: %s" % id(propdict)
for i in range(3):
test()
$ python /tmp/test.py
propdict id: 135258836
propdict id: 135258836
propdict id: 135258836
I can't imagine that holding true universally; what happens if you
return the propdict, and modify it elsewhere?
Python does cache unused objects (i.e., go to an interpreter and run
"id(object())" over and over and you get the same id). But the moment
you hold a reference to an object, id(object()) will start giving a new id.
Yes, so it obviously depends on how you use it, but simply returning a
dictionary won't cause new objects to be created every time by itself.
Although, I'd certainly accept the argument that because of this
subtlety in behaviour it should not be relied on.
-Shawn
_______________________________________________
caiman-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/caiman-discuss