Python 类型错误:';类型';对象不可下标。如何从二维阵列中删除阵列?

Python 类型错误:';类型';对象不可下标。如何从二维阵列中删除阵列?,python,arrays,typeerror,Python,Arrays,Typeerror,我看过类似问题的答案,但我就是做不到。我对python还很陌生 def read(): set = [] f = open("error set 1.txt", "r") replace = f.read() f.close() f = open("Test1_Votes.txt", "w") replaced = replace.replace(",", "") f.write(replaced) f.close()

我看过类似问题的答案,但我就是做不到。我对python还很陌生

def read():

    set = []
    f = open("error set 1.txt", "r")
    replace = f.read()
    f.close()

    f = open("Test1_Votes.txt", "w")
    replaced = replace.replace(",", "")
    f.write(replaced)
    f.close()



    f = open("Test1_Votes.txt", "r")
    for line in f:
        ballot = []


        for ch in line:

            vote = ch

            ballot.append(vote)

        print (ballot)

        set.append(ballot)


    """print(set)"""
    remove()

def remove():
    for i in range (70):
        x = i - 1
        check = set[x]
        if 1 not in check:
            set.remove[x]
    print(set)
错误是第37行,检查=设置[x]
我不确定是什么导致了
删除
功能中的错误,您尚未定义
设置
。因此,python认为它是内置对象
,实际上它是不可订阅的


将对象传递给
删除
函数,最好给它另一个名称。

删除
函数中,您没有定义
设置
。因此,python认为它是内置对象
,实际上它是不可订阅的

将对象传递给
remove
函数,最好给它另一个名称。

你的remove函数无法“看到”你设置的变量(即列表,避免使用保留字作为变量名),因为它不是公共的,只在read函数中定义。 在读取函数之前定义此变量,或将其作为输入发送以删除函数,则该变量应正常工作

def read():
    set = []
    f = open("error set 1.txt", "r")
    replace = f.read()
    f.close()

    f = open("Test1_Votes.txt", "w")
    replaced = replace.replace(",", "")
    f.write(replaced)
    f.close()

    f = open("Test1_Votes.txt", "r")
    for line in f:
        ballot = []


    for ch in line:
        vote = ch
        ballot.append(vote)

    print (ballot)

    set.append(ballot)


    """print(set)"""
    remove(set)

def remove(set):
    for i in range (70):
        x = i - 1
        check = set[x]
        if 1 not in check:
            set.remove(x)
    print(set)
remove函数无法“查看”设置的变量(即列表,避免使用保留字作为变量名),因为它不是公共的,只在read函数中定义。 在读取函数之前定义此变量,或将其作为输入发送以删除函数,则该变量应正常工作

def read():
    set = []
    f = open("error set 1.txt", "r")
    replace = f.read()
    f.close()

    f = open("Test1_Votes.txt", "w")
    replaced = replace.replace(",", "")
    f.write(replaced)
    f.close()

    f = open("Test1_Votes.txt", "r")
    for line in f:
        ballot = []


    for ch in line:
        vote = ch
        ballot.append(vote)

    print (ballot)

    set.append(ballot)


    """print(set)"""
    remove(set)

def remove(set):
    for i in range (70):
        x = i - 1
        check = set[x]
        if 1 not in check:
            set.remove(x)
    print(set)

“下标”是指将
[…]
添加到某物上。您不能在
set
上使用
[x]
。你希望它做什么?避免使用
python
关键字,例如
set
作为变量名。“下标”意味着向某个对象添加
[…]
。您不能在
set
上使用
[x]
。您希望它做什么?避免使用
python
关键字,例如
set
作为变量名。