[Python-Dev] Class Methods

D-Man dsh8290 at rit.edu
Mon Apr 23 13:11:54 EDT 2001


On Fri, Apr 20, 2001 at 05:40:21PM +0200, Thomas Heller wrote:
| I want the class methods (for example) to create and manipulate
| this 'context object'. This object, however, belongs into the class...
| 
| What I want to avoid is
| 
|   class X(...):
|       ....
|   initialize(X)

Here is a different approach to consider :

class X :
    def __class_init__( class_X ) :
        initialize( class_X )


The idea here is to provide a "magic" method in the class that the
interpreter calls as soon as the class object exists.  The first
(only) argument is the class object, which can be named as desired
(analogous to 'self').  The main problem here is clients aren't
prevented from calling this method, and they really shouldn't.

-D





More information about the Python-list mailing list