Globals or objects?

Mel mwilson at the-wire.com
Thu Feb 21 10:11:52 EST 2008


James Newton wrote:
> Duncan Booth wrote:
>> The easiest way in Python to implement a singleton is just to
>> use a module: all modules are singletons and there is a
>> defined mechanism (import) for accessing them.
[ ... ]
> Could you give a bare-bones demonstration of it that the relative newbie
> that I am can understand?

I had a club-membership application that ran for several years. 
Default pathnames, etc. for the particular year came from a module 
called thisyear.py:
#=========================


'''Values used to access this years trakkers files.
$Id: thisyear.py,v 1.2 2006/08/26 16:30:23 mwilson Exp $
'''

memberpath = '2006-7/20062007.txt' # path to this years membership CSV
dirname = '2006-7' # directory name for this year


#=========================
Programs that needed to use the comma-separated-value membership base 
would import thisyear, and pass thisyear.memberpath when creating the 
CSV reader object.  Etc.



	Mel.



More information about the Python-list mailing list