每当我尝试运行此代码时:
#Open file
f = open("i.txt", "r")
line = 1
#Detect start point
def findstart( x ):
length = 0
epsilon = 7
a = 3
line_value = int(f.readline(x))
if line_value == a:
length = length + 1
x = x + 1
findend(x)
elif line_value == epsilon:
x = x + 2
findstart(x)
else:
x = x + 1
findstart(x)
#Detect end point
def findend(x):
line_value = int(f.readline(x))
if line_value == a:
length = length + 1
return ("Accept", length)
elif line_value == epsilon:
x = x + 2
length = length + 2
findend(x)
else:
x = x + 1
length = length + 1
findend(x)
findstart(line)
我得到这个错误代码:
Traceback (most recent call last):
File "C:\Users\Brandon\Desktop\DetectSequences.py", line 39, in <module>
findstart(line)
File "C:\Users\Brandon\Desktop\DetectSequences.py", line 16, in findstart
findend(x)
File "C:\Users\Brandon\Desktop\DetectSequences.py", line 26, in findend
line_value = int(f.readline(x))
ValueError: invalid literal for int() with base 10: ''
谁能帮我找出问题所在?在我看来,它正在尝试读取一个空单元格,但我不知道为什么会这样。我正在扫描的文件目前只有两行,每行读数为“3”,所以它应该输出成功,但我无法克服这个错误。