magic names in python

Josiah Carlson josiah.carlson at sbcglobal.net
Mon Jun 4 03:18:51 EDT 2007


per9000 wrote:
> So my questions:
>  * is there a comprehensive list of magic names in python (so far i
> know of __init__ and __repr__)?
>  * are these lists complete or can magic names be added over time (to
> the python "core")?
>  * are magic names the same in different python versions?

I don't believe that there is a full list of all __magic__ methods.  The 
operator module has a fairly extensive listing of functions that call 
such methods, but I know that some have been left out.

Among those that I remember off the top of my head while typing this 
message...

__init__
__new__
__str__
__repr__
__len__
__nonzero__
__hash__
__cmp__ (__eq__, __ne__, __lt__, __gt__, __le__, __ge__)
__getattr__
__setattr__
__delattr__
__getitem__
__setitem__
__delitem__
__iter__
__neg__
__not__

There's also the not-magic named, but still somewhat magic .next() 
method on iterators/generators.

  - Josiah




More information about the Python-list mailing list