Python 3 - ValueError:未转换的数据仍然存在:

时间:2017-02-22 22:05:03

标签: python windows

这些让我很困惑。我正在尝试编辑最初调用另一个python脚本(sun.py)的python脚本(hue-flux.py)来返回一个值作为其进程的一部分。目标是sun.py独立运行,创建一个txt文件,在两行(总共两个值)上有两个值,master.py读取而不是为它调用sun.py。基本上它们是日出和日落时间。我已成功获取sun.py来写入值,但是当试图让hue-flux.py读取值的txt文件而不是调用sun.py时,我遇到了错误。

以下是我编辑之前的原始代码:

sunrise_time = sun.get_sun(location)[0]
print (sunrise_time)
sunset_time = sun.get_sun(location)[1]  # Sunset time in 24hr format
print (sunset_time)
fadetime = get_secs_to_hour(sunset_time)

和编辑后的代码:

with open("c:\\users\\snipped\\suntimes.txt", mode='r') as f:
    lines = f.readlines()
    sunrise_time = lines[0]
    sunset_time = lines[1]  # Sunset time in 24hr format
    print ((sunrise_time),end = '')
    print ((sunset_time),end = '')
sunrisefadetime = get_secs_to_hour(sunrise_time)
print (sunrisefadetime)
sunsetfadetime = get_secs_to_hour(sunset_time)

以下是我尝试运行已编辑代码时的结果:

====================== RESTART: C:\Python36\hue-flux.py ======================
Discovering Hue bridges...
Found previously connected bridge
7:13
17:34Traceback (most recent call last):
  File "C:\Python36\hue-flux.py", line 290, in <module>
    sunrisefadetime = get_secs_to_hour(sunrise_time)
  File "C:\Python36\hue-flux.py", line 254, in get_secs_to_hour
    return time.mktime(time.strptime(today + hour, "%x%H:%M")) - time.time()
  File "C:\Python36\lib\_strptime.py", line 559, in _strptime_time
    tt = _strptime(data_string, format)[0]
  File "C:\Python36\lib\_strptime.py", line 365, in _strptime
    data_string[found.end():])
ValueError: unconverted data remains: 

>>> 

任何人都可以提供任何帮助吗?操作系统是Windows Server 2012 R2。原始脚本位于https://github.com/KpaBap/hue-flux,但原作者似乎没有响应。

0 个答案:

没有答案