【问题标题】:How do I cut the last characters and save them?如何剪切最后一个字符并保存它们?
【发布时间】:2020-11-05 23:01:57
【问题描述】:

我有一个创建未压缩公钥的脚本生成器。该脚本适用于 "bitcoin" 模块。

因此,我得到了由 130 十六进制字符组成的未压缩公钥。

我是04 [x, y]

我需要更改代码,以便只将最后一个 25 字符保存在结果中。也就是说,要剪切公钥并保存到文件中 “Pubkey.txt”

import bitcoin

with open("Privkey.txt","r") as f:
    content = f.readlines()
# you may also want to remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content]
f.close()


outfile = open("Pubkey.txt","w")
for x in content:
  outfile.write(""+bitcoin.privtopub(x)+"\n")

outfile.close()

【问题讨论】:

    标签: python python-3.x list python-2.7 python-requests


    【解决方案1】:

    如果bitcoin.privtopub(x) 返回一个字符串,那么你可以对它进行切片。

    bitcoin.privtopub(x)[-25:]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      相关资源
      最近更新 更多