problems with class initiation

Magnus Lie Hetland mlh at
Sun Jul 1 16:15:48 EDT 2001

"Iñigo Serna" <inigoserna at> wrote in message
news:mailman.994017363.31520.python-list at
> I suppose the error comes due to Main class hasn't finished its
> initiation when 'app.prefs.a' is executed so app is None in that moment.

The assignment isn't finished, so app is indeed None. Instead of
relying on global variables, you should supply app as a parameter
to the constructor of Second, IMO... Thus:

class Second:
    def __init__(self, app):
        return self.init_fn(app)
    def init_fn(self, app):
        return app.prefs.a

class Main:
    def __init__(self):
        self.prefs = Preferences()
        self.fns = []

... or something like that. (The design seemed slightly confusing to me,
but I think this should work, at least :)


  Magnus Lie Hetland

 "Reality is that which, when you stop believing in
  it, doesn't go away."           -- Philip K. Dick

More information about the Python-list mailing list