Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x TypeError:列表索引必须是整数,而不是_io.TextIOWrapper_Python 3.x - Fatal编程技术网

Python 3.x TypeError:列表索引必须是整数,而不是_io.TextIOWrapper

Python 3.x TypeError:列表索引必须是整数,而不是_io.TextIOWrapper,python-3.x,Python 3.x,我试图在文本文档中搜索某个数字。它可以很好地读取文件,以后使用相同的代码可以很好地打印,但是当我告诉它在文本文档中查找某个数字时,它告诉我TypeError:列表索引必须是整数,而不是_io.TextIOWrapper。我环顾了四周,但所有的问题都说‘not str’,而我的问题说‘not _io.TextIOWrapper’ 这是我的代码(我将沿着“菜单选项”下的路线“A”) import time import linecache print("Welcome to the League F

我试图在文本文档中搜索某个数字。它可以很好地读取文件,以后使用相同的代码可以很好地打印,但是当我告诉它在文本文档中查找某个数字时,它告诉我
TypeError:列表索引必须是整数,而不是_io.TextIOWrapper
。我环顾了四周,但所有的问题都说‘not str’,而我的问题说‘not _io.TextIOWrapper’

这是我的代码(我将沿着“菜单选项”下的路线“A”)

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("Please enter the fixture number you are looking for... ")
    fixtureQuestion = input(int())
    fixtureQuestion = int(fixtureQuestion)
    fixtureQuestion = fixtureQuestion - (1)
    time.sleep(3)
    if fixtureQuestion < 1:
        print("This fixture is not available, please re-run the application...")
        time.sleep(2)
        exit()
    elif fixtureQuestion > 190:
        print("This fixture is not available, please re-run the application...")
        time.sleep(2)
        exit()
    else:
        searchData = open("Y:\Computing & Business\Students\Computing\Year 10\CA 2017 Edexcel\\firesideFixtures.txt")
        lines = searchData.readlines()
        print(lines[searchData])
        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("Searching for fixtures...")
    time.sleep(3)
    data = [line.strip() for line in open(r"Y:\Computing & Business\Students\Computing\Year 10\CA 2017 Edexcel\firesideFixtures.txt").readlines()]
    for line in data:
        print(line)
    time.sleep(1)
    print("Return to menu?")
    menuReturn = input("Y or N")
    if menuReturn == 'Y':
        print("Press A to search for a fixture")
        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 == 'A':
            fixtureQuestion = input(int("Please enter the fixture number you are looking for... "))
            fixtureQuestion = fixtureQuestion - 1
            time.sleep(3)
            if fixtureQuestion < 1:
                print("This fixture is not available, please re-run the application...")
                time.sleep(2)
                exit()
            elif fixtureQuestion > 190:
                print("This fixture is not available, please re-run the application...")
                time.sleep(2)
                exit()
            else:
                searchData = open(r"Y:\Computing & Business\Students\Computing\Year 10\CA 2017 Edexcel\firesideFixtures.txt").readlines()
                lines = searchData.readlines()
                print(lines[fixtureQuestion])
                time.sleep(1)
                print("Return to menu?")
                menuReturn = input("Y or N")
                if menuReturn == 'Y':
                    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 == 'C':
                        print("~~incomplete~~")
                    elif menuOptions2 == 'Q':
                        print("Exiting Application...")
                        time.sleep(1)
                        exit()
                elif menuReturn == 'N':
                    print("Exiting Application...")
                    time.sleep(2)
                    exit()
                elif menuOptions2 == 'Q':
                    print("Exiting Application...")
                    time.sleep(1)
                    exit()
elif menuOptions == 'C':
    while RetryForC == "Yes":
        RetryForC == "No"
        fireRead = open("Y:\Computing & Business\Students\Computing\Year 10\CA 2017 Edexcel\firesideResults.txt")
        for line in fireRead:
            fireRead = open("Y:\Computing & Business\Students\Computing\Year 10\CA 2017 Edexcel\firesideResults.txt")
            InfoOne = line.split(',')[0]
            InfoTwo = line.split(',')[1]
            InfoThree = line.split(',')[2]
            InfoFour = line.split(',')[3]
            PointCounter = int(line.split(',')[2])
            PointCounter = PointCounter * 3
            fireRead.close()
            print("Player:",InfoOne,"Has played:",InfoTwo,", has won:",InfoThree,", has lost:",InfoFour,", and therefore has",PointCounter,"many points.")
        print("Retry?")
        RestForC = str(input("Yes/No  "))
    print("The program will now close...")
    time.sleep(5)
    exit()
elif menuOptions == 'Q':
    print("Exiting Applicaion...")
    time.sleep(2)
    exit()
导入时间
导入行缓存
打印(“欢迎来到联赛赛程经理!”)
时间。睡眠(3)
打印(“您想做什么?”)
时间。睡眠(1)
打印(“按A键搜索固定装置”)
睡眠时间(0.1)
打印(“按B键查看未完成的固定装置”)
睡眠时间(0.1)
打印(“按C键显示导板”)
睡眠时间(0.1)
打印(“或按Q退出,这将退出应用程序。”)
睡眠时间(0.1)
menuOptions=input(“您想做什么?A、B、C或Q.”)
如果菜单选项=='A':
打印(“请输入您要查找的夹具编号…”)
fixtureQuestion=输入(int())
fixtureQuestion=int(fixtureQuestion)
fixtureQuestion=fixtureQuestion-(1)
时间。睡眠(3)
如果fixtureQuestion<1:
打印(“此设备不可用,请重新运行应用程序…”)
时间。睡眠(2)
退出()
elif fixtureQuestion>190:
打印(“此设备不可用,请重新运行应用程序…”)
时间。睡眠(2)
退出()
其他:
searchData=open(“Y:\Computing&Business\Students\Computing\Year 10\CA 2017 Edexcel\\firesideFixtures.txt”)
lines=searchData.readlines()
打印(行[搜索数据])
时间。睡眠(1)
打印(“返回菜单?”)
菜单返回=输入(“Y或N”)
如果menuReturn='Y':
打印(“按B键查看未完成的固定装置”)
睡眠时间(0.1)
打印(“按C键显示排行榜”)
睡眠时间(0.1)
打印(“或按Q退出应用程序”)
睡眠时间(0.1)
打印(“现在您已看到设备列表,无法查看该列表,但可以向上滚动以再次查看该列表。”)
睡眠时间(0.1)
menuOptions2=输入(“您想做什么?B、C或Q?”)
如果菜单选项2=='B':
打印(“~~不完整~~”)
elif菜单选项2=='C':
打印(“~~不完整~~”)
elif菜单选项2=='Q':
打印(“正在退出应用程序…”)
时间。睡眠(1)
退出()
elif menuReturn='N':
打印(“正在退出应用程序…”)
时间。睡眠(2)
退出()
elif菜单选项=='B':
打印(“搜索装置…”)
时间。睡眠(3)
数据=[line.strip(),用于开放的行(r“Y:\Computing&Business\Students\Computing\Year 10\CA 2017 Edexcel\firesideFixtures.txt”).readlines()]
对于行输入数据:
打印(行)
时间。睡眠(1)
打印(“返回菜单?”)
菜单返回=输入(“Y或N”)
如果menuReturn='Y':
打印(“按A键搜索夹具”)
睡眠时间(0.1)
打印(“按C键显示排行榜”)
睡眠时间(0.1)
打印(“或按Q退出应用程序”)
睡眠时间(0.1)
打印(“现在您已看到设备列表,无法查看该列表,但可以向上滚动以再次查看该列表。”)
睡眠时间(0.1)
menuOptions2=输入(“您想做什么?B、C或Q?”)
如果菜单选项2=='A':
fixtureQuestion=输入(int(“请输入您要查找的夹具编号…”)
fixtureQuestion=fixtureQuestion-1
时间。睡眠(3)
如果fixtureQuestion<1:
打印(“此设备不可用,请重新运行应用程序…”)
时间。睡眠(2)
退出()
elif fixtureQuestion>190:
打印(“此设备不可用,请重新运行应用程序…”)
时间。睡眠(2)
退出()
其他:
searchData=open(r“Y:\Computing&Business\Students\Computing\Year 10\CA 2017 Edexcel\firesideFixtures.txt”).readlines()
lines=searchData.readlines()
打印(行[fixtureQuestion])
时间。睡眠(1)
打印(“返回菜单?”)
菜单返回=输入(“Y或N”)
如果menuReturn='Y':
打印(“按C键显示排行榜”)
睡眠时间(0.1)
打印(“或按Q退出应用程序”)
睡眠时间(0.1)
打印(“现在您已看到设备列表,无法查看该列表,但可以向上滚动以再次查看该列表。”)
睡眠时间(0.1)
menuOptions2=输入(“您想做什么?B、C或Q?”)
如果菜单选项2=='C':
打印(“~~不完整~~”)
elif菜单选项2=='Q':
打印(“正在退出应用程序…”)
时间。睡眠(1)
退出()
elif menuReturn='N':
打印(“正在退出应用程序…”)
时间。睡眠(2)
退出()
elif菜单选项2=='Q':
打印(“正在退出应用程序…”)
时间。睡眠(1)
退出()
elif菜单选项=='C':
而RetryForC==“是”:
RetryForC==“否”
fireRead=open(“Y:\Computing&Business\Students\Computing\Year 10\CA 2017 Edexcel\firesideResults.txt”)
对于fireRead中的行:
fireRead=open(“Y:\Computing&Business\Students\Computing\Year 10\CA 2017 Edexcel\firesideResults.txt”)
InfoOne=line.split(',')[0]
InfoTwo=line.split(',')[1]
信息三
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
Please enter the fixture number you are looking for... 
016
Traceback (most recent call last):
  File "E:\Python\Python Work\League\League3.py", line 33, in <module>
    print(lines[searchData])
TypeError: list indices must be integers, not _io.TextIOWrapper
print(lines[searchData])
>>> my_list = [1, 2, 3]
>>> my_list[0]
1