python - while 循环永远不会结束(python)
问题描述
尝试过检查生成的私钥是否长度相等,但程序会卡在这个 while 循环中?
private_key_hex = '{:x}'.format(private_key_dec)
print ("Length of private_key_hex: ", len(str(private_key_hex)))
while (len(private_key_hex) % 2) != 0:
private_key_hex = '{:x}'.format(private_key_dec)
print("Private key (Hex): " + private_key_hex) # this never happens...
解决方案
即使不知道 的来源private_key_dec
,我也可以看到您正在循环一个字符串,并且由于您没有更改 的值private_key_dec
,因此您实际上private_key_hex
每次都重新分配给相同的值。
因此,如果它进入 while 循环,它永远不会离开。
一种解决方案是将您分配private_key_dec
给一个列表,而不是while
循环,使用一个for
循环到这个列表。但为了更准确,请详细说明您接收数据的格式。
推荐阅读
- docker - RabbitMQ 集群:无法将从节点加入到主节点
- c++ - 我应该包含谷歌测试的头文件或源文件吗?
- highcharts - 如何在 Highcharts 中创建规范的 3d 图?
- python - 如何将一维信号转换为二维信号?
- node.js - 如果与 bluebird map 函数一起使用,Iteratee 函数会在 javascript 中丢失对此对象的引用
- angular - Angular 8 - 构建生产路线不起作用
- reactjs - Reactjs 中的动画
- python - statsmodels anova_lm 是否需要与 scipy f_oneway anova 相同的假设?
- pandas - 使用 pandas 数据框有效地搜索数据
- python - python tkinter pandas搜索功能的问题