Global in multiple files

Chris Barker chrishbarker at home.net
Mon Jun 11 20:05:00 EDT 2001


> (Ruby seems elegant, also I spare some finger-gimnastics when
> I have to change indentation of a whole function only because I
> added one condition etc.)

get yourself an editor that is Python-aware (Emacs, PythonWin, Scite,
etc.). It will let you increase or decrease the indentation of a block
of code easily. Then you will be spared the finger gymnastics of typing
all those darn braces and semicolons!

> (BTW I would like to thank other people for pointing out the
> possibility of having global.py module etc. Yes, it solves my
> problem for now, but maybe I should really redesign it as Roman
> suggest to eliminate the need. No, I still don't know how :))

Maybe, but the idea of a module as a storage place for an assortment of
data that you want to access from lots of places is a good one. Those
FORTRAN common blocks were good for something, you know! Just be careful
about over-using it. I tend to reserve it for things that are only set
once, and then only read by various other modules later, if a piece of
data is being changed by a lot of different modules, it may not belong
there.

As far a OO design is concerned, a module used in this way is very much
like a class with only one instance. It's just a little less code. IN
fact, it may make sense to put accessor functions in your globals
module, like:

globals.getUserList()

rather than explicity accessing the global value itself.

-Chris







-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list