Python: NameError: free variable 're' referenced before assignment in enclosing scope -
i have strange nameerror in python 3.3.1 (win7).
the code:
import re # ... # parse exclude patterns. excluded_regexps = set(re.compile(regexp) regexp in options.exclude_pattern) # line 561: excluded_regexps |= set(re.compile(regexp, re.i) regexp in options.exclude_pattern_ci)
the error:
traceback (most recent call last): file "py3createtorrent.py", line 794, in <module> sys.exit(main(sys.argv)) file "py3createtorrent.py", line 561, in main excluded_regexps |= set(re.compile(regexp, re.i) regexp in options.exclude_pattern_ci) file "py3createtorrent.py", line 561, in <genexpr> excluded_regexps |= set(re.compile(regexp, re.i) regexp in options.exclude_pattern_ci) nameerror: free variable 're' referenced before assignment in enclosing scope
note line 561, error occurs, second line in code above. in other words: re
not free variable. regular expression module , can referenced fine in first line.
it seems me reference re.i
causing problem, don't see how.
most likely, assigning re
(presumably inadvertently) @ point below line 561, in same function. reproduces error:
import re def main(): term = re.compile("foo") re = 0 main()
Comments
Post a Comment