Module variables
Hans Nowak
zephyr01 at alltel.net
Wed May 28 12:57:05 EDT 2003
Cameron Zemek wrote:
> Okay I have been translating some pascal into python.
Been reading Jack Crenshaw's compiler tutor, eh? :-)
> 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.
Rather than having a bunch of procedures, you could create a class and use
methods. E.g.
class Parser:
def __init__(self, input):
self.Look = ''
self.input = input
self.index = 0
def GetChar(self):
try:
self.Look = input[index]
index = index + 1
except:
self.Look = '\n'
...etc...
> Also what is the naming convention for variables and functions that are
> internal to the module?
There's no real convention, but some people use the _ prefix to indicate this.
Ditto for objects.
HTH,
More information about the Python-list
mailing list