現在、テキストファイルを読み込み、それをPythonシェルに印刷しようとしています。それは完璧にファイルを読み込みますが、読み込んだ行を別々に読み出すと、AttributeErrorがあることがわかります。どうすればこの問題を解決できますか?AttributeError: 'list'オブジェクトに属性 'readlines'がありません(Python 3.4.4)
は、ここに私のコードです:
import time
import linecache
print("Welcome to the League Fixture Manager!")
time.sleep(3)
print("What would you like to do?")
time.sleep(1)
print("Press A to search for a fixture.")
time.sleep(0.1)
print("Press B to view Outstanding fixtures.")
time.sleep(0.1)
print("Press C to display the leader board")
time.sleep(0.1)
print("Or press Q to quit, this will exit the application.")
time.sleep(0.1)
menuOptions = input("What would you like to do? A, B, C, or Q.")
if menuOptions == 'A':
print("Searching for fixtures...")
time.sleep(3)
data = [line.strip() for line in open("Y:/Computing & Business/Students/Computing/Year 10/CA 2017 Edexcel/firesideFixtures.txt").readlines()]
lines = data.readlines()
print(data)
time.sleep(1)
print("Return to menu?")
menuReturn = input("Y or N")
if menuReturn == 'Y':
print("Press B to view outstanding fixtures.")
time.sleep(0.1)
print("Press C to display the leaderboard")
time.sleep(0.1)
print("Or press Q to exit the application.")
time.sleep(0.1)
print("You cannot review the fixture list now you have seen it however you can scroll up to view it again.")
time.sleep(0.1)
menuOptions2 = input("What would you like to do? B, C, or Q?")
if menuOptions2 == 'B':
print("~~incomplete~~")
elif menuOptions2 == 'C':
print("~~incomplete~~")
elif menuOptions2 == 'Q':
print("Exiting Application...")
time.sleep(1)
exit()
elif menuReturn == 'N':
print("Exiting Application...")
time.sleep(2)
exit()
elif menuOptions == 'B':
print("~~incomplete~~")
elif menuOptions == 'C':
print("~~incomplete~~")
elif menuOptions == 'Q':
print("Exiting Applicaion...")
time.sleep(2)
exit()
そして、これは私が受け取るものです:あなたがリストにreadlines
を適用しようとしている
Welcome to the League Fixture Manager!
What would you like to do?
Press A to search for a fixture.
Press B to view Outstanding fixtures.
Press C to display the leader board
Or press Q to quit, this will exit the application.
What would you like to do? A, B, C, or Q.A
Searching for fixtures...
Traceback (most recent call last):
File "E:\Python\Python Work\League\League3.py", line 20, in <module>
lines = data.readlines()
AttributeError: 'list' object has no attribute 'readlines'
オープン(R "Yのラインのために、'データ= [line.strip()としてdata' 'の割り当てを交換してみてください:\コンピューティング&ビジネス\ Students \ Computing \ Year 10 \ CA 2017 Edexcel \ firesideFixtures.txt ")。readlines()]'。 – Gahan
ありがとうございますが、これは結果には何の差もなく、以前と同じように印刷されます。 – Foxy