Guyz,我在下面的代码中遇到了以下错误,你哪里出错了?任何清理建议也被接受
for line in file(timedir + "/change_authors.txt"):
UnboundLocalError: local variable 'file' referenced before assignment
下面的代码:
import os,datetime
import subprocess
from subprocess import check_call,Popen, PIPE
from shutil import copyfile,copy
def main ():
#check_call("ssh -p 29418 review-droid.comp.com change query --commit-message status:open project:platform/vendor/qcom-proprietary/radio branch:master | grep -Po '(?<=(email|umber): )\S+' | xargs -n2")
global timedir
change=147441
timedir=datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
#changeauthors = dict((int(x.split('/')[3]), x) for line in file(timedir + "/change_authors.txt"))
for line in file(timedir + "/change_authors.txt"):
changeauthors = dict(line.split()[0], line.split()[1])
print changeauthors[change]
try:
os.makedirs(timedir)
except OSError, e:
if e.errno != 17:
raise # This was not a "directory exist" error..
with open(timedir + "/change_authors.txt", "wb") as file:
check_call("ssh -p 29418 review-droid.comp.com "
"change query --commit-message "
"status:open project:platform/vendor/qcom-proprietary/radio branch:master |"
"grep -Po '(?<=(email|umber): )\S+' |"
"xargs -n2",
shell=True, # need shell due to the pipes
stdout=file) # redirect to a file
if __name__ == '__main__':
main()