在 python 2.xa 中u
表示它是一个 unicode 对象,但它与字符串对象非常相似,要将其转换为原始数据,只需使用str()
方法或int()
方法
>>> type(u'K-DawG')
<type 'unicode'>
>>> type('K-DawG')
<type 'str'>
>>> type(str(u'K-DawG'))
<type 'str'>
但是在 python 3.x中,一个 unicode 对象被视为一个string,所以在你的情况下,一个int()
方法就是转换被认为是一个字符串的数字所需要的全部
>>> type(u'K-DawG')
<class 'str'>
>>> type(int(u'12'))
<class 'int'>
要将日期作为字符串而不是作为datetime.date
对象获取,请使用以下.isoformat()
方法:
data = {
'date': datetime.date(2018, 9, 30).isoformat(),
'Number': int(u'4929000000006'),
}
print(data)
这将打印:{'Number': 4929000000006, 'date': '2018-09-30'}
注意:我直接使用datetime.date(2018, 9, 30)
而不是kwargs['this_number']
因为,您没有说明更多信息或没有暴露更多需要的代码,我所说的必须足够