[Edu-sig] Python Pedagogy

Dethe Elza delza at livingcode.org
Fri Jul 21 19:12:46 CEST 2006


kirby urner wrote:
>> 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
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
> 


class Anthro(object):

     def __init__(my):
         I = me = my
         my.self = me
         my.truism = (phrase for phrase in ['I am', 'that which I am'])

     def __repr__(my):
         return my.truism.next()

     def who(my):
         I = me = my
         print me, my.self and I

if __name__ == '__main__': Anthro().who()


--Dethe


More information about the Edu-sig mailing list