Python刚执行了1行

时间:2018-11-05 14:24:48

标签: python loops sha256

嗨,我是python代码的新手。我试图编写一个程序来从十六进制生成私钥。 我像.txt那样制作一个十六进制列表 80000000000000000000000000000000000000000000000000000000000

并导入到代码

当我尝试执行文件时,仅执行第一行 而txt文件中有5行

是否有一种方法可以执行所有列表? 我的代码错误在哪里?

output_file = open("output.txt", "w")

# Step 2: let's add 80 in front of it
with open("generate.txt", "r") as extended_key:
    data = extended_key.readline().replace("\n", "")


# Step 3: first SHA-256
first_sha256 = hashlib.sha256(binascii.unhexlify(data)).hexdigest()
# Step 4: second SHA-256
second_sha256 = hashlib.sha256(binascii.unhexlify(first_sha256)).hexdigest()
# Step 5-6: add checksum to end of extended key
final_key = data+second_sha256[:8]
# Step 7: finally the Wallet Import Format is the base 58 encode of final_key
WIF = base58.b58encode(binascii.unhexlify(final_key))

output_file.write (WIF)

2 个答案:

答案 0 :(得分:0)

您应该使用readlines()获取包含所有行的列表,然后在该列表上循环。

答案 1 :(得分:0)

以此替换上面的句段。 fileOb.read()读取全部内容,而fileOb.readline()仅读取一行。

# Step 2: let's add 80 in front of it
with open("generate.txt", "r") as extended_key:
    data = extended_key.read().replace("\n", " ") #to read all the lines and replace the newline characters by spaces