0
我要搜索用戶的輸入值,但只有在該行的第一部分搜索一行文件行線的第一部分(蟒蛇)
def optionA():
fixnum = input("What is the fixture number of the game?")
with open("firesideFixtures.txt") as f:#open the file as "f"
for line in f:#search each line
if str(fixnum) in line:#search each line for the user input
print(line)#print the line
optionA()
的問題是它的打印每與其中的夾具號碼一致。我需要它只打印夾具號碼是第一個字符的那個。
這裏的文件:
1,02/09/15,18:00,RNGesus,Ingsoc,Y,Ingsoc
2,03/09/15,18:00,M'lady,Napoleon Wilson,Y,Napolean Wilson
的Python 2將與您認爲Fixnum對象並不總是一個字符串;) –