首页 > 解决方案 > 如何解决散列时python中的内存错误

问题描述

该程序通过 GUI 获取文件。我正在为 GUI 使用 tkinter。打印目录中的文件,然后以按钮的形式打印功能的数量。每个按钮执行特定的操作。为传递的文件创建一个哈希。哈希值将打印在屏幕上。

import hashlib as hl
import tkinter as tkin
# prints the list of files on screen
def files_list():
    arr= os.listdir()
    row_number=next(row)
    column_number=0
    for i in arr:
        array_lable=tkin.Label(root,text=i).grid(row=row_number,column=column_number)
        column_number+=1
        if column_number==5:
            column_number=0
            row_number=next(row)
def file_processor(file_name):    
    if file_name not in os.listdir():
        error="file not found"
        error_lable=tkin.Label(root,text=error,bg='red')
        error_lable.grid(row=next(row),column=0)
    file= open(file_name, 'rb')
    file_content= file.read()
    return file_content
def hash_printer(value,file_name):
    value=value.hexdigest()
    text="The hash value for {} is {}".format(file_name,value)
    Lable=tkin.Label(root,text=text)
    Lable.grid(row=next(row),column=0)
def md5():
    file_name=inputt.get()
    file_content= file_processor(file_name)
    hash_value= hl.md5(file_content)
    hash_printer(hash_value,file_name)
def create_button(text,function_name):
    md5=tkin.Button(root,text=text,command= function_name)
    md5.grid(row=button_row,column=next(column_of_button))
row=iter(list(range(100)))
column_of_button=iter(list(range(7)))
root=tkin.Tk()
inputt=tkin.Entry(root,width=65,borderwidth=5)
inputt.grid(column=0, row=next(row), columnspan=5) 
files_list()
functions={md5:"MD5"}
button_row=next(row)
for key in functions:
    create_button( functions[key], key)
root.mainloop()

标签: pythonout-of-memory

解决方案


推荐阅读