Class 我得到一个索引超出范围错误

Class 我得到一个索引超出范围错误,class,python-3.x,object,Class,Python 3.x,Object,我的函数获取表单字典中的一个表,并在应用了该人员询问的查询后返回该表。我有其他几种方法,但我在使用等条件方法时遇到了问题。这就是我尝试过的 class Table(): def where_con(self,table,conditions): for condition in conditions: if ('='in condition): print(table.get_dict()) print(condition

我的函数获取表单字典中的一个表,并在应用了该人员询问的查询后返回该表。我有其他几种方法,但我在使用等条件方法时遇到了问题。这就是我尝试过的

class Table():

def where_con(self,table,conditions):
    for condition in conditions:
        if ('='in condition):
            print(table.get_dict())
            print(condition)
            self = table.equal_condition(table,condition)
            return(self) 

        elif('>'in condition):
            new_table = table.greater_condition(table, condition)
            return(self)           

def equal_condition(self,table,condition):
    '''(Table, string) -> Table
    This Function takes in a table and a condition and applies the 
    condition and returns a new table with the condition applied 
    REQ: Table must have the contents of the condition
    REQ: The condition must have proper syntax
    REQ: The condition must contain the equal sign in string form 
    '''
    number_rows = table.num_rows()
    print(number_rows)
    dictionary = table.get_dict()
    print(dictionary)
    condition = condition.split('=')
    print(condition)
    #new_table = Table()
    # Adding Coloums Name in Self 
    for col in dictionary:
        self.add_column({col: []})

    # If the Second part is a string    
    if ("'" in condition[1]):
        condition[1] = condition[1].strip("'")  
        i=0
        while(i<number_rows):
            print(i)
            i=i+1
            if (dictionary[condition[0]][i] == condition[1]):
                for key in self.get_dict():
                    self = self.update_column(key,dictionary[key][i])
            #i=i+1
    else:
        i=0
        while(i<number_rows):
            print(i)
            if (dictionary[condition[0]][i] == dictionary[condition[1]][i]):
                for key in self.get_dict():
                    self.update_column(key,dictionary[key][i])
            i=i+1

    return self
class表():
def,其中_con(自身、表格、条件):
对于条件中的条件:
如果(条件中的“=”):
打印(table.get_dict())
打印(条件)
self=表格。相等条件(表格,条件)
返回(自我)
elif(条件中的“>”):
新表格=表格。更大的表格条件(表格,条件)
返回(自我)
def相等条件(自身、表格、条件):
''(表格,字符串)->表格
此函数接受一个表和一个条件,并应用
条件,并返回应用该条件的新表
REQ:表必须包含条件的内容
REQ:条件必须具有正确的语法
REQ:条件必须包含字符串形式的等号
'''
number_rows=table.num_rows()
打印(行数)
dictionary=table.get_dict()
印刷(字典)
条件=条件.拆分('='))
打印(条件)
#新表=表()
#在Self中添加列名称
对于字典中的col:
self.add_列({col:[]})
#如果第二部分是字符串
如果条件[1]中的(“”):
条件[1]=条件[1]。条带(“”)
i=0
而(i>a=Table()
>>>a、 设置标题({'w.Critical_rating':['5','5','5','5','o.for':['Directing','Acting','Directing','Acting','w.title':['Titanic','Titanic','Avatar','Avatar'],'o.Titanic','Avatar','Titanic'],'w.your_rating':['4.5','5','w.average_rating':['4.75','4.75','5']))
>>>d=表()
>>>f=其中(a,“w.title=o.title”)
4.
{'o.for':['Directing'、'Acting'、'Directing'、'Acting']、'o.title':['Avatar'、'Titanic'、'Avatar'、'Titanic'、'w.评论家评分':['5'、'5']、'w.your'U评分':['4.5'、'4.75'、'5'、'5'、'w.title':['Titanic'、'Avatar'、'Avatar']
['w.title','o.title']
0
回溯(最近一次呼叫最后一次):
Python Shell,提示符2,第1行
文件“C:\Users\Abhinav\Desktop\MAde\u answer\database.py”,第205行,在
如果(字典[条件[0]][i]==字典[条件[1]][i]):
builtins.Indexer错误:列表索引超出范围

发生这种情况的原因以及我如何修复它。非常感谢您的帮助。

您的表对象没有属性“set\u dict”?而且num\u rows()似乎没有定义您的代码在这里不完整:“update\u column”定义也丢失了您的表对象没有属性“set\u dict”?还有num\u rows()似乎未定义此处的代码不完整:“更新列”定义也丢失
>>>a = Table()
>>>a.set_dict({'w.critic_rating': ['5', '5', '5', '5'], 'o.for':     ['Directing', 'Acting', 'Directing', 'Acting'], 'w.title': ['Titanic', 'Titanic', 'Avatar', 'Avatar'], 'o.title': ['Avatar', 'Titanic', 'Avatar', 'Titanic'], 'w w.your_rating': ['4.5', '4.5', '5', '5'], 'w.average_rating': ['4.75', '4.75',  '5', '5']})
>>>d = Table()
>>>f = where_con(a,"w.title=o.title")
4
{'o.for': ['Directing', 'Acting', 'Directing', 'Acting'], 'o.title': ['Avatar', 'Titanic', 'Avatar', 'Titanic'], 'w.critic_rating': ['5', '5', '5', '5'], 'w.your_rating': ['4.5', '4.5', '5', '5'], 'w.average_rating': ['4.75', '4.75', '5', '5'], 'w.title': ['Titanic', 'Titanic', 'Avatar', 'Avatar']}
['w.title', 'o.title']
0
Traceback (most recent call last):
Python Shell, prompt 2, line 1
File "C:\Users\Abhinav\Desktop\MAde_answer\database.py", line 205, in    <module>
if (dictionary[condition[0]][i] == dictionary[condition[1]][i]):
builtins.IndexError: list index out of range