以下是代码:
def measure_lister(Location):
dont_crash=os.listdir(Location)
measure={}
for name in dont_crash:
temp=function("%s//%s"%(Location,name))
measure[name]=temp
所以dont_crash只是一个目录中的文件名列表,并且该函数不重要但它创建了一个包含三个元素的元组。 Python一直说最后一行是语法错误。我在shell中尝试了完全相同的代码并且它工作正常,但是python仍然拒绝编译代码。帮助!
编辑:这是确切的代码:
def measure_lister(Location,Baseline):
dont_crash=os.listdir(Location)
measure={}
for name in dont_crash:
temp=f_measures("%s\\%s"%(Location,name),int(name[17:20],baseline_file=Baseline)
measure[name]=temp
这是我得到的错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\owner\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "C:/Users/owner/Desktop/diff_output_all/lists.py", line 1210
measure[name]=temp
^
SyntaxError: invalid syntax
答案 0 :(得分:0)
尝试将功能更改为:
def measure_lister(Location,Baseline):
dont_crash=os.listdir(Location)
measure={}
for name in dont_crash:
temp=f_measures("%s\\%s"%(Location,name),int(name[17:20]),baseline_file=Baseline)
measure[name]=temp
我认为你在函数f_measures,
的调用中缺少a)按照Martijn的建议编辑
希望它有所帮助!