class declaration shortcut
Arnaud Delobelle
arnodel at googlemail.com
Fri Mar 2 12:03:08 EST 2007
On Mar 2, 3:01 pm, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n... at spamgourmet.com> wrote:
> Steven D'Aprano wrote:
> > Overkill? Storage of a single attribute holding a (usually short)
> > string is overkill?
>
> No, but storing the first name a class is bound to in it is a bit
> of, IMHO.
Don't see it as the first name a class is bound to, but rather as the
name a class is defined as.
If class_object.__name__ == 'Foo' it means that somewhere in your code
there is a class definition:
class Foo:
# stuff
Same for function: if function_object.__name__ == 'bar' it means that
somewhere you have
def bar(...):
# stuff
(Of course this is not the case if you use another way to define
functions or classes, e.g. type() )
> > When you do that, you wouldn't expect the __name__ of
> > some.module.function to change to f, and it doesn't.
>
> But what is it for then? =) Showing the first name the class was
> bound to?
What I described above is quite useful I think. The alternative
(anonymous classes) is that given an object myobj you have no means to
find out what its class is (by that I mean to be able to locate the
class definition in your source code), apart from stabbing in the dark
(i.e. trying type(myobj)==someclass until successful).
--
Arnaud
More information about the Python-list
mailing list