(newbie) Is there a way to prevent "name redundancy" in OOP ?
Laszlo Nagy
gandalf at designaproduct.biz
Fri Jan 5 14:19:33 EST 2007
Stef Mientki wrote:
> Not sure I wrote the subject line correct,
> but the examples might explain if not clear
>
>
> *** first attempt ***
> class pin:
> def __init__ (self):
> self.Name = 'Unknown Pin'
>
> aap = pin() # create an instance
> aap.Name = 'aap' # set it's name
> print aap.Name # print it's name
>
> # but why should I set it's name ??
> print 'aap' # I can just as well print a constant string !!
> # (ok there will be an extra check)
>
If you are trying to determine the name of your object, then you do not
know what 'name' and 'object' means in Python. In this case, I recommend
you this:
http://effbot.org/zone/python-objects.htm
In particular, pay attention to that objects can have zero or more names.
This is how you can create three unnamed objects:
L = [pin(),pin(),pin(),]
This is how you can bind three names to the same object:
p1 = p2 = p3 = pin()
Maybe I did not understand you question.
Laszlo
More information about the Python-list
mailing list