Who am I: can a class instance determine its own name?
paulp at ActiveState.com
Sun Mar 11 16:39:15 CET 2001
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.
More information about the Python-list