execution time with global variables
me at privacy.net
Fri Jul 2 12:33:51 CEST 2004
sarmin kho <sarmin_kho at yahoo.com> wrote in
news:mailman.346.1088760869.27577.python-list at python.org:
> i have been using a lot of global variables in the python script i am
> working on. the global variables are shared and used by all various
> 'definitions' :
> def name ():
> global all globs...
> my question is: 'is it safe using global variables in term of its
> execution time?
Is the program running fast enough? If so, the answer is 'yes'. If not then
using local variables might provide some speedup, but usually changing your
algorithm is a better way to optimise.
> i cant think of any other ways not to use the globs because some
> variables simply have to be shared among those definitions..
The usual solution is to define a class and then all your globals simply
become attributes within the class. Try doing it that way and see if you
More information about the Python-list