[Tutor] __init__ for class instantiation?

Zak Arntson zak@harlekin-maus.com
Fri Apr 25 15:41:21 2003


>>
>> My question is: Is there a function I can define in the base Thing
> class
>> which would run once Player (or any other Thing child) has been
> fully
>> defined? Or is my current solution as close as I can get?
>
> The short answer is no I don't believe so, not as such.
> The definition of a class doesn't (except at a very deep secret
> level) trigger any action in Python so you can't force it to
> do anything.
>
> You could maybe play some tricks with class constructor functions
> that return a Thing class after running your magic method.
>
 <SNIP!>
> Normally you wouyld do it at the instance level, is there any reason why
> you can't do that? ie. Wait till the class is instantiated...
>
> Alan G

My best current solution is to do just that. I can do it via __init__, but
this means the function I want to run once upon the class's definition is
actually called with every instance of the class. But I'm not going to
stress about the CPU cycles caused by this :)

-- 
Zak Arntson
www.harlekin-maus.com - Games - Lots of 'em