gpt4 book ai didi

python - 将返回的 urlopen() 转换为 float

转载 作者:行者123 更新时间:2023-11-30 23:37:18 26 4
gpt4 key购买 nike

尝试让它工作,但不断收到“ValueError:无法将字符串转换为 float :”错误。我尝试过 read() 和 readline() 但无法弄清楚。

感谢您的帮助!

from urllib2 import urlopen
current_time = urlopen("http://just-the-time.appspot.com/?f=%t")
print current_time.readline()

future = float(current_time.readline()) + 30
print "future" + future

最佳答案

已经读取了之前行中的值。只需阅读一次:

current_time = urlopen("http://just-the-time.appspot.com/?f=%t")
current_time = current_time.read()

future = float(current_time) + 30

关于python - 将返回的 urlopen() 转换为 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15709872/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com