Re: [Newbie] Referring to a global variable inside a function

2006-04-10 Thread bruno at modulix
Ernesto García García wrote: > Hi experts, > > I've built a class for parsing a user-defined list of files and matching > lines with a user-defined list of regular expressions. It looks like this: > (snip code) > > But then, when I try to use my class using actions with "memory" it will > fail:

Re: [Newbie] Referring to a global variable inside a function

2006-04-09 Thread Ernesto García García
>>How would you do this? > > def line_action(line, match_dictionary): > global count # make it a module-global variable, not a function-local > count = count + 1 > > OK, I had put it on the global block. Thanks, Ernesto -- http://mail.python.org/mailman/listinfo/python-lis

Re: [Newbie] Referring to a global variable inside a function

2006-04-09 Thread Fredrik Lundh
Ernesto García García wrote: > But then, when I try to use my class using actions with "memory" it will > fail: > > > import LineMatcher > > global count > count = 0 > > def line_action(line, match_dictionary): >count = count + 1 > > line_matcher = LineMatcher.LineMatcher() > line_matcher.add

[Newbie] Referring to a global variable inside a function

2006-04-09 Thread Ernesto García García
Hi experts, I've built a class for parsing a user-defined list of files and matching lines with a user-defined list of regular expressions. It looks like this: import re import glob class LineMatcher: """ Parses a list of text files, matching their lines with the given regular expression