name of an instance

Terry Reedy tjreedy at udel.edu
Mon Nov 1 14:03:42 EST 2004


"andrea valle" <andrea.valle at unito.it> wrote in message 
news:6FAE7CBE-2BF1-11D9-841C-0003939C968C at unito.it...
>How do I access the name of an instance?

By giving __init__ a name param that you store as self.name so that the 
instance really has a name.  (def and class statements do something 
similar)
---
class MyClass:
  def __init__(self, name='No name'):
    self.name = name
  def __str__(self): return self.name

Terry J. Reedy






More information about the Python-list mailing list