Cookbook idea - single-shot __init__

Ben Finney bignose-hates-spam at and-zip-does-too.com.au
Wed Jul 23 22:17:39 EDT 2003


On Wed, 23 Jul 2003 19:15:23 -0600, Bob Gailer wrote:
> I have at times had the need to initialize some things once at the
> class level

In Python 2.2 (earlier?) you can define any attribute at the class
level, and it will be shared by all instances:

    class Foo( object ):
        grumble = 0.1
        flibble = {}
        def __init__( self ):
            ''' Instance initialisation '''
            return

This causes the attributes 'grumble', 'flibble', and '__init__()' to be
shared by all Foo instances; anything done within __init__() will affect
the individual instance only.

-- 
 \      "I stayed up all night playing poker with tarot cards. I got a |
  `\               full house and four people died."  -- Steven Wright |
_o__)                                                                  |
http://bignose.squidly.org/ 9CFE12B0 791A4267 887F520C B7AC2E51 BD41714B




More information about the Python-list mailing list