Yes, I would say avoid globals like a pest! They are used by folks familiar with C/C++ programming, where passing arguments, particularly multiple arguments are a possible pointer nightmare.
Here is an example where a global might be useful ...
[php]x = 0
def incr_x() :
"""here x changes, so declare as global, or get an error"""
global x
x += 1
return x
print incr_x() # 1
print incr_x() # 2
print incr_x() # 3
# should x change within the program you can get surprises
# here x is inadvertently used in a loop
for x in range(78):
y = x + x
# later, you might expect 4
print incr_x() # 78 oops!
[/php]You can make it less likely to get global errors by assigning a recognizable namespace to all globals ...
[php]# a class to the rescue, to give all global variables a namespace
class Global(object):
"""declare all global variables here"""
x = 0
z = False
# now you can give all global variables a namespace (the class instance)
# use something like ww (from WorldWide) for a recognizable namespace for global variables
ww = Global()
print ww.x # 0
print ww.z # False
def incr_wwx() :
"""here ww.x changes, but does not have to be declared global"""
ww.x += 1
return ww.x
print incr_wwx() # 1
print incr_wwx() # 2
print incr_wwx() # 3
[/php]