Liam Clarke wrote:
Hi all,

I've got a module called foo.py

foo.py -

import parrot

class Bar(model.Background):

    def __initialize__(self, event):
             #Just a pythoncard variant on init
             self.config=self.loadCfg()


def loadCfg(): #get some cfg stuff, return as dict return cfgDict

   def on_aBtn_mouseClick(self, event):
         parrot.Sketch()

app=Bar(main.application)
app.mainloop()


If I wanted the function parrot.Sketch() to access that config dictionary, I would reference it as

foo.app.config?

Is that right?

Yes, after import foo but it's really ugly and a very bad idea. You should do something different like parrot.Sketch(self.config) or even put the config into a module of its own if you really want a globally available configuration.

OK, so why is this so bad? Because foo and parrot depend on each other. Neither one can be used independently. You can't test parrot.Sketch() without creating a foo.app. You can't reuse parrot.Sketch() in another module named bar. You can't even restructure foo.py to make app a local variable of a main() function, for example.

Don't do this. Really. This way lies spaghetti code and intractable bugs and throwing the whole mess away and starting over doing it right this time.

Try to organize your modules so the dependencies form an acyclic directed graph. In other words, don't have any dependency cycles like foo depends on parrot depends on foo.

Kent


Regards,

Liam Clarke

_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Reply via email to