我试图将日期格式为“06/01/05”(月/日/年)的CSV文件读入App Engine(Python)中的DateProperty(而不是DateTimeProperty)。以下是我目前的情况:
for row in mycsvfiledata:
obj = MyObject()
datetemp = row[1]
cohorttemp = datetime.datetime.strptime(datetemp, "%m/%d/%y")
obj.cohort_date.month = cohorttemp.month
obj.cohort_date.day = cohorttemp.day
obj.cohort_date.year = cohorttemp.year
我得到了一个错误: [... 省略…] 对象队列日期.月=同室温度月 AttributeError:“NoneType”对象没有“month”属性
我也试过:
^{pr2}$(但是strptime似乎只生成一个datetime对象,而不是一个date对象)
obj.cohort_date = datetime.datetime.strptime(datetemp, "%m/%d/%y")
(但是“quentue_date”是App Engine中的一个DateProperty,当我尝试时,我得到“BadValueError:Property quention_date必须是日期,而不是datetime”)
如果我只将“quention_date”设置为DateTimeProperty,那么一切都很好,但我不想这样(出于各种原因)。如果你能给我一些指导,我会很感激的!在
datetime
实例有一个date()
方法,该方法返回相应的date
实例,因此:相关问题 更多 >
编程相关推荐