Module variables

Carl Banks imbosol at aerojockey.com
Wed May 28 14:53:01 EDT 2003


Cameron Zemek wrote:
> Okay I have been translating some pascal into python. I need to have
> variables with module scope. atm I'm doing this with "global" in methods
> that need to update the global variable. Is there a way todo this that
> doesn't need each function to declare what global variables it will need.

Just think of the "global" statements as the declarations you've
always wanted in Python.  It's not really much of a step down, since
you have to declare variables in Pascal anyways.

Python encourages good programming practive by considering all
variables local until proven global.  Meanwhile, other languages
beginning with "P" that shall remain nameless encourage poor
programming by considering all variables global until declared local.


> Also what is the naming convention for variables and functions that are
> internal to the module?

As others have said, preceded by an underscore is most common.


-- 
CARL BANKS




More information about the Python-list mailing list