md5(str.encode(var1)).hexdigest() 给出十六进制值为 382fbe213f159eecf85facb256f265d0 - 如何知道 var1?

问题描述

在运行测试用例时,我的代码失败,因为十六进制的预期值与我的答案不同。

例如,我的 ws_std 值为 13.06,即 var1

md5(str.encode(var1)).hexdigest()  giving hex value as 382fbe213f159eecf85facb256f265d0 

但我不确定它是否与十六进制值匹配。

在下面的代码中出错:-

variables = ["ws_std","p_range","corr","dew_month","max_gust_month","max_gust_value","avg_temp","temp_range","max_p_range_day","num_days_std","median_b_days"]
answers = [ws_std,p_range,corr,dew_month,max_gust_month,max_gust_value,avg_temp,temp_range,max_p_range_day,num_days_std,median_b_days]

answer_dict = dict()

for var,ans in zip(variables,answers):
    answer_dict[var] = md5(str.encode(ans)).hexdigest()

with open('test_files/hash.pk','rb') as file:
    hash_dict = pickle.load(file)


def test_ws_std():
    assert hash_dict["ws_std"] == answer_dict["ws_std"]

错误代码:-

========================================================== FAILURES ==========================================================
________________________________________________________ test_ws_std _________________________________________________________

    def test_ws_std():
>       assert hash_dict["ws_std"] == answer_dict["ws_std"]
E       AssertionError: assert 'c8cc550afa85...2c6946c238f36' == '382fbe213f159...facb256f265d0'
E         - c8cc550afa85496c4ee2c6946c238f36
E         + 382fbe213f159eecf85facb256f265d0

test.py:40: AssertionError

解决方法

见下面的评论。 需要输出:ws_std