why static methods?

Uwe Schmitt uwe.schmitt at procoders.net
Thu Feb 20 03:43:00 EST 2003


Tim Peters <tim.one at comcast.net> wrote:
> [Gerrit Holl]
>> What is the purpose of static methods? I do not understand the
>> difference with a function outside the class.

> Good!  That's because there is no difference.  It's purely a namespace
> thing.  Especially if you define multiple related classes in a single
> module, say A and B, then A.return_something() and B.return_something() can
> be clearer than needing to make up two distinct names at the module global
> level.  Defining a static method in the class body also gives it easy access
> to whatever "private names" the class may use; writing it outside the class
> means you'd have to simulate Python's name-mangling by hand.

That is a good explanation. Can you explain the differences
between static- and class-functions, too ?

Greetings, Uwe.



-- 
Dr. rer. nat. Uwe Schmitt      Computer science is no more about Computers,
uwe.schmitt at num.uni-sb.de      than astronomy is about telescopes. (Dijkstra)
http://www.procoders.net           




More information about the Python-list mailing list