Who am I: can a class instance determine its own name?

Kevin Cazabon kevin_cazabon at hotmail.nospamplease!.com
Mon Mar 12 05:28:31 CET 2001


The reason I say it's not elegant is that there is the possibility (read
"probability") that the assigned name and the actual name can differ.

We're assuming that the programmer assigns exactly the same name to both,
which doesn't seem like a hard task, but it introduces the possibility of
problems, and probably hard ones to debug too.

If there were an automatic method, it would be MUCH more reliable.

Just MHO.

Kevin.



"Paul Prescod" <paulp at ActiveState.com> wrote in message
news:mailman.984324974.25480.python-list at python.org...
| Kevin Cazabon wrote:
| >
| > ...
| > You could also
| > make it an initialization parameter.
| >
| > FooBar = Foo(name="FooBar")
| >
| > Just trying to help... not elegantly though.
|
| I disagree Kevin. This is not only the canonical way to give an instance
| a name, it is also the elegant way. It gives you a lot more flexibility
| because the name it has at runtime is unrelated to the variable name you
| happened to have given it in your code. If you need to change one or the
| other for any reason, you can do so safely.
|
|  Paul Prescod
|





More information about the Python-list mailing list