[Edu-sig] Python Pedagogy

kirby urner kirby.urner at gmail.com
Fri Jul 21 18:18:52 CEST 2006


> Note that rover.self raises an exception.  self is not an 'attribute'
> of an object but a way for code to gain a reference to the specific
> instance "from within".  This instance is perhaps best conceptualized
> as a discrete chunk of memory somewhere (something to be garbage
> collected when no longer referenced externally).

Note:  if you wanted, you could make self an attribute by assigning it
to an instance variable:

>>> class Human:
	def __init__(self, name):
		self.name = name
		self.self = self

		
>>> o = Human('Bob')
>>> o
<__main__.Human instance at 0x00D0D198>
>>> o.self
<__main__.Human instance at 0x00D0D198>

I can't think of any reason to do this off hand.

Kirby


More information about the Edu-sig mailing list