Brian Forney <bforney at cs.wisc.edu> writes: > Hi, > > I am trying to use eval in Python 2.0. I am trying to use reo.sub() and a > method that compiles and eval()'s some code from a text file to perform > flexible replacements. Unfortunately, I see a TypeError in string.py: > > Traceback (most recent call last): > File "test.py", line 27, in ? > reo.sub(subClass.subFN, str); > File "/s/python-2.0.0//lib/python2.0/sre.py", line 115, in _sub > return _subn(pattern, template, string, count)[0] > File "/s/python-2.0.0//lib/python2.0/sre.py", line 140, in _subn > return _join(s, string[:0]), n > File "/s/python-2.0.0//lib/python2.0/sre.py", line 89, in _join > return string.join(seq, sep[:0]) > File "/s/python-2.0.0//lib/python2.0/string.py", line 129, in join > return sep.join(words) > TypeError: sequence item 1: expected string, None found [schnipp] > def subFN(self, matchObj): > expr = matchObj.group('expr'); > compObj = compile(expr, '<string>', 'exec'); When you compile a piece of code to exec, it returns None. > return eval(compObj, {'path':self.__path}); so this returns None, which causes your problems. Try compiling with "single" instead. Not sure this will work, but it might (depending what code you're trying to execute). Cheers, M. -- The rapid establishment of social ties, even of a fleeting nature, advance not only that goal but its standing in the uberconscious mesh of communal psychic, subjective, and algorithmic interbeing. But I fear I'm restating the obvious. -- Will Ware, comp.lang.python
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4