ValueError:未转换的数据仍然保留:02:05 [英] ValueError: unconverted data remains: 02:05
本文介绍了ValueError:未转换的数据仍然保留:02:05的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import os
import time
from datetime import datetime
from pytz import timezone
input_file = file(FILE,r)
j = json.loads(input_file .read()。decode(utf-8-sig))
os.environ ['TZ'] ='CET'
用于j中的项目:
lt = time.strftime('%A%d%B')
st = item ['start']
st = datetime.strptime(st,'%A%d%B' )
如果st == lt:
item ['start'] = datetime.strptime(st,'%H:%M')
我有这样的错误:
文件/home/--/--/--/app/route.py,第35行,在file.py
st = datetime.strptime(st,'%A%d% B')
文件/usr/lib/python2.7/_strptime.py,第328行,_strptime
data_string [found.end():])
ValueError:未转换的数据仍然保留:02:05
你有什么建议吗?
解决方案
st c < = datetime.strptime(st,'%A%d%B')
行类似于 01 01 2013 02:05
和 strptime
无法解析这个。事实上,你会收到一个小时的日期...你需要添加%H:%M
在你的strptime。
I have some dates in a json files, and I am searching for those who corresponds to today's date :
import os
import time
from datetime import datetime
from pytz import timezone
input_file = file(FILE, "r")
j = json.loads(input_file.read().decode("utf-8-sig"))
os.environ['TZ'] = 'CET'
for item in j:
lt = time.strftime('%A %d %B')
st = item['start']
st = datetime.strptime(st, '%A %d %B')
if st == lt :
item['start'] = datetime.strptime(st,'%H:%M')
I had an error like this :
File "/home/--/--/--/app/route.py", line 35, in file.py
st = datetime.strptime(st, '%A %d %B')
File "/usr/lib/python2.7/_strptime.py", line 328, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: 02:05
Do you have any suggestions ?
解决方案
The value of st
at st = datetime.strptime(st, '%A %d %B')
line something like 01 01 2013 02:05
and the strptime
can't parse this. Indeed, you get an hour in addition of the date... You need to add %H:%M
at your strptime.
这篇关于ValueError:未转换的数据仍然保留:02:05的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文