Prev: [ANN] Oktest 0.3.0 released - a new style testing library
Next: Using site-packages with alt-installed Python version
From: Chris Rebert on 16 May 2010 04:40 On Fri, May 14, 2010 at 7:32 AM, AON LAZIO <aonlazio(a)gmail.com> wrote: > Hi, > Â Â Say I have an application which requires a global settings for the user. > When the user finishes setting those global variables for the app. Any class > can use that variables (which are the same for all), something like that. > What is the suitable mechanism for this solution? Have a module that either contains the variables directly or contains a configuration object that has the variables. Then just import the module wherever you need to access the variables. For example: #config.py power_user_mode = True user_avatar = "bacon.jpg" #elsewhere.py import mypackage.config as config class Foo(object): #... def whatever(self): self.set_avatar(config.user_avatar) if config.power_user_mode: self.show_advanced_interface() #... def something(self): new_avatar = self.avatar_chooser() config.user_avatar = new_avatar self.set_avatar(new_avatar) Cheers, Chris -- Why bacon? Reddit. http://blog.rebertia.com |