[Edu-sig] Python for Beginners

John Posner jjposner at snet.net
Mon May 26 15:28:18 CEST 2008


> 
> Right, as long as by "zero names" you're ruling out any 
> pointers to pointers through a data structure, ...

Are you referring to this situation:

  IDLE 1.2.1      
  >>> import sys
  >>> a = 'this is a really unique value'
  >>> sys.getrefcount(a)
  2
  >>> dict01 = { 'first' : a, 'second' : 2 }
  >>> sys.getrefcount(a)
  3
  >>> dict02 = { 'uno' : a, 'dos' : 222 }
  >>> sys.getrefcount(a)
  4


> ... which are 
> anonymous from another angle (the structure itself has a 
> name, but the objects may be like Rod(color="Red"), with 
> color choosing the length behind the scenes. d =  
> {"red":Rod()} is then a string literal mapped to an object, 
> *like* a top-level name, but not.  d is the top-level name in 
> this namespace.  Rod( ) in a sense has no name, is a call to 
> a constructor that returned on object captured within a 
> dictionary.  So it won't be garbage collected, as it knows 
> there's this pointer for some reason (for what reason the 
> object will have no clue).

"Rod() in a sense has no name" ??

Doesn't the Rod object get the name "red" in *almost exactly* the same way
in these two cases?

  Case #1:   >>> red = Rod()

  Case #2:   >>> d = { "red" : Rod() }

In Case #1, the name "red" is created in the local (or maybe global)
namespace. In Case #2, the name "red" is created in the namespace of a
dictionary object. In the sticky-note metaphor:

  a dictionary object is just a collection of sticky-notes


-John Posner



More information about the Edu-sig mailing list