我编写了一些Python3.4代码,它们确实正确执行,但是当使用不同的IDE来帮助我查找错误时,我会在这个代码片段中的赋值错误之前得到一个引用的变量:
if os.path.isfile(o.options_file): # Make sure this really is a file.
options = (csv.reader(open(o.options_file), delimiter='\t'))
else:
exit("Options_File Not Found. Check File Name and Path.")
count = 0
for line in options:
count += 1抛出错误的是options变量。这是否可以被忽略,或者我是否应该为选项分配一个空值?
发布于 2015-03-25 17:15:32
你可以倒转测试:
if not os.path.isfile(o.options_file): # Make sure this really is a file.
exit("Options_File Not Found. Check File Name and Path.")
options = (csv.reader(open(o.options_file), delimiter='\t'))
count = 0
for line in options:
count += 1这使得代码分析工具和其他开发人员更加清楚地认识到,如果文件不存在,其余的代码就不会运行。
https://stackoverflow.com/questions/29262175
复制相似问题