Python中的哈希函数生成错误

Python中的哈希函数生成错误,python,hash,Python,Hash,因此,我试图掌握散列函数以及它们是如何工作的。我有下面的代码,但是当我试着运行代码时,我总是得到一个错误 import sys def part_one(): foo = open('input_table.txt') for line in foo: id, make, model, year = line.split(",") print(make, model) tuple

因此,我试图掌握散列函数以及它们是如何工作的。我有下面的代码,但是当我试着运行代码时,我总是得到一个错误

import sys 

def part_one():   

        foo = open('input_table.txt')
        for line in foo:
            id, make, model, year = line.split(",")
            print(make, model) 
            tuple_list = (make+model,)
        return tuple_list



def hash_one(num_buffers, tuple_list):
        #part_one()
    # A being the first constant prime number to multiply by
    # B being the prime number that we add to A*sum_of_chars
        tuple_list = part_one()
        A = 3
        B = 5
        count = 0 

        for item in tuple_list:
            for char in item:
        # sum_of_chars is the total of each letter in the word
                count = ord(char)
                count = count + tuple_list
        index = ((A * sum_of_chars + B)) % num_buffers
        return index    



if __name__ == '__main__':

    input_table = sys.argv[1] 
    num_buffers = int(sys.argv[2])
    chars_per_buffer = int(sys.argv[3])
    sys.argv[4] = 'make'
    sys.argv[5] = 'model'
    lst = []
    for item in range(4, len(sys.argv)):
        lst.append(sys.argv[item])
    print(lst)
    hash_one(lst)
导致错误的代码有什么问题?有人能帮我吗?

1 如果在没有参数的情况下调用
hash()
,则必须散列某些内容

一个数字的散列只会返回相同的数字,所以它不是很有趣。它是用来散列字符串之类的东西的

2.
part\u one
不返回任何内容,因此当您调用
tuple\u list=part\u one()
时,它的值设置为
None
,并且您不能对其进行迭代

3. 通过参数传入一个列表,然后覆盖它,无论如何都没有任何意义。如果要返回列表,请使用
return
语句

4. 在代码中设置参数变量很奇怪,它们用于从命令行读取内容

五,

(不是错误,而是…)
您可以使用切片(
lst=sys.argv[4://code>)作为获取列表子部分的更简单方法。

您还可以添加收到的
错误
?请说明您获取的错误、行等。它给了我一个类型错误行48和行29。这里没有行号。包括完整的回溯(错误报告)。