Cookbook idea - single-shot __init__

Ian Bicking ianb at colorstudy.com
Thu Jul 24 00:29:28 EDT 2003


On Wed, 2003-07-23 at 21:17, Ben Finney wrote:
> 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:

This is true in all versions of Python.  However, there are some
instances where you can't initialize the attributes at class creation
time, and you want to delay initializing those variables until some
later time.  This usually is a problem of circular dependencies, or
where initialization somehow depends on the overall context of the
program (like configuration variables that may not be fully read by the
time the module is imported).

  Ian







More information about the Python-list mailing list