Unbound Local error? How?
Hari Sekhon
sekhon.hari at googlemail.com
Tue Jun 27 10:54:55 EDT 2006
Diez B. Roggisch wrote:
> Hari Sekhon wrote:
>
>
>> import re
>> re_regexname = re.compile('abc')
>>
>> .....
>> ..... various function defs
>> .....
>>
>> def func1():
>> ...
>> func2()
>> ...
>>
>> def func2():
>> if re_regexname.match('abc'):
>> <do something>
>>
>> if __name__ == '__main__':
>> func1()
>>
>
>
> The above clearly is not what you have. See the attached version of the
> above that works. So - go check for a typo or something like that.
>
> Diez
> ------------------------------------------------------------------------
>
> import re
> re_regexname = re.compile('abc')
>
> def func1():
> func2()
>
> def func2():
> if re_regexname.match('abc'):
> print " whohoo!"
>
> if __name__ == '__main__':
> func1()
>
you're right, it wasn't that, I was trying to locally override a regex
object as follows:
re_somepattern = re.compile('abc')
re_someotherpattern = re.compile('def')
def func():
if somecondition:
re_somepattern = re_someotherpattern
<code block>
re_somepattern.match('something')
</code.block>
not sure how to override this the way I want, it'd be quite messy if I
had to do huge if blocks to handle this inside the other code blocks
that use this re_somepattern.match()
or perhaps I'm going about this all wrong....
-h
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060627/62737abd/attachment.html>
More information about the Python-list
mailing list