Python Error when imported from different directory -
in mydir/test/testing/pqtest.py
import os,sys lib_path = os.path.abspath('../../lib/mine') sys.path.append(lib_path) import util <---- traceback import string import random # code
traceback (most recent call last): file "pqtest.py", line 5 in ? import util file "mydir/lib/mine/util.py", line 89 yield v if l > 0 else '' error point @ if syntaxerror: invalid syntax
however, there other files import util.py inside mydir/lib/mine
not have problems file.
so why giving me traceback when importing somewhere else, in case mydir/test/testing
?
syntax error on yield v if l > 0 else ''
def expand(): l,v in zip(field,val): yield l yield v if l > 0 else ''
this python 2.5 not python 2.4
i assuming need tell pqtest.py use python 2.5 not sure how
if you're willing change util.py, obvious thing rewrite code it's 2.4 compatible. comment, reason not change util.py is:
… others depending on python 2.5.
but long new code has exact same effect on python 2.5+ original code, isn't problem.
for example, instead of this:
def expand(): l,v in zip(field,val): yield l yield v if l > 0 else ''
do this:
def expand(): l,v in zip(field,val): yield l if l > 0: yield v else: yield ''
now other people depending on python 2.5 have no change, work in 2.4.
Comments
Post a Comment