[英]Python Indentation confusion of template code
I'm getting this error unindent does not match any outer indentation level
on the line我收到此错误
unindent does not match any outer indentation level
on the line
if line.find('ubox')>0
I'm not very experienced with python but pressing Shift Tab in my IDE does not fix the problem.我对 python 不是很有经验,但在我的 IDE 中按 Shift Tab 不能解决问题。 This is the template code from one of my assignments so when I copy pasted it must have messed up the indentation.
这是我的一项作业中的模板代码,所以当我复制粘贴时,它一定弄乱了缩进。 In the text file given, if lines up for but just eyeballing the code I would have thought it was a nested if in the elif.
在给定的文本文件中,如果排队但只是盯着代码,我会认为它是 elif 中的嵌套 if。
def parse_dot_ps_file(filepath):
'''
Parsing of a dot.ps file that contains result of RNAfold program
@args:
filepath: (full or relative) path to the dot.ps.
@return:
dot_ps_result: list f lists with i, j, freq_i_j
'''
dot_ps_result = []
with open(filepath, 'r') as f:
is_data = False
for line in f:
if not is_data and line.startswith('%start of base pair probability data'):
is_data = True
continue
elif is_data and line.startswith('showpage'):
break
elif is_data:
if line.find('ubox') > 0:
# take only first 3 numbers
data_line = line.split()[:3]
dot_ps_result.append(
[int(data_line[0]), int(data_line[1]), float(data_line[2])]
)
return dot_ps_result
The interpreter expects something to be found under elif is_data:
, but instead it found nothing.解释器希望在
elif is_data:
下找到一些东西,但它什么也没找到。 So either fill it with your code, or if you meant the line if line.find('ubox') > 0:
to execute if the elif is_data:
condition executes then fix your indentation.因此,要么用您的代码填充它,或者如果您的意思是
if line.find('ubox') > 0:
则在elif is_data:
条件执行时执行,然后修复您的缩进。
if line.find('ubox') > 0:
# take only first 3 numbers
#these two lines below are the problem
data_line = line.split()[:3]
dot_ps_result.append([int(data_line[0]), int(data_line[1]), float(data_line[2])])
You also have an else statement with no code beneath it, so the indentation is hanging, what do you want the script to do there?你还有一个下面没有代码的 else 语句,所以缩进挂了,你想让脚本在那里做什么? All you need is
pass
and that would be fine你只需要
pass
就可以了
You have put too many tabs in this section.您在此部分中放置了太多选项卡。
Hope that helps希望有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.