magic names in python

markacy markacy at gmail.com
Mon Jun 4 09:35:50 EDT 2007


On 4 Cze, 08:43, per9000 <per9... at gmail.com> wrote:
> Hi,
>
> I recently started working a lot more in python than I have done in
> the past. And I discovered something that totally removed the pretty
> pink clouds of beautifulness that had surrounded my previous python
> experiences: magic names (I felt almost as sad as when I discovered
> the strange pink worms that eat you in nethack, not to mention the
> mind flayers - I really hate them).
>
> I guess all programming languages have magic names to some extent
> (f.x. classes in the "C-family" have constructors that must have the
> same name as the class (foo::foo) instead of foo.__init__).
>
> I just used a search engine a little on this topic and I found no
> comprehensive list of magic names in python.
>
> 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 also tried (selected parts of(?)) the unittest package for use in
> Zope and it seemed functions that I created for my test with the magic
> prefix "test" were magic, other functions were not.
>
> So another question emerges:
>  * is the use of magic names encouraged and/or part of good coding
> practice.
>
> Live long and prosper,
> Per
>
> --
>
> Per Erik Strandberg
> home:www.pererikstrandberg.se
> work:www.incf.org
> also:www.spongswedencare.se

On "magic" methods and their usage You can read here:
http://diveintopython.org/object_oriented_framework/special_class_methods.html
By the way - this is a very good book on python.
Cheers,
Marek




More information about the Python-list mailing list