Python structseq()与time.struct_time有关的错误

Python structseq()与time.struct_time有关的错误,python,time,python-2.7,Python,Time,Python 2.7,这是给出错误的python脚本: >>> import time >>> t=[ ] >>> t.append(time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0,tm_min=0,tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1)) Traceback (most recent call last): Fil

这是给出错误的python脚本:

>>> import time
>>> t=[ ]        
>>> t.append(time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0,tm_min=0,tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: structseq() takes at most 2 arguments (9 given)
导入时间 >>>t=[] >>>t.append(time.struct_time(tm_year=2000,tm_mon=11,tm_mday=30,tm_hour=0,tm_min=0,tm_sec=0,tm_wday=3,tm_yday=335,tm_isdst=-1)) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 TypeError:structseq()最多接受2个参数(给定9个) 这一个也给出了相同的错误:

>>> import time 
>>> t=time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0,tm_min=0,tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: structseq() takes at most 2 arguments (9 given)
导入时间 >>>t=time.struct\u time(tm\u year=2000,tm\u mon=11,tm\u mday=30,tm\u hour=0,tm\u min=0,tm\u sec=0,tm\u wday=3,tm\u yday=335,tm\u isdst=-1) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 TypeError:structseq()最多接受2个参数(给定9个)
time.struct\u time
希望它的第一个参数是一个包含9个元素的序列:

In [58]: time.struct_time((2000,11,30,0,0,0,3,335,-1))
Out[58]: time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1)
但请注意,这会过度指定日期时间

例如,您可以将2000年1月1日指定为具有
tm_yday=100
,这显然是不正确的:

In [72]: time.struct_time((2000,1,1,0,0,0,3,100,-1))
Out[72]: time.struct_time(tm_year=2000, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=100, tm_isdst=-1)
因此,最好使用datetime并调用其timetuple()方法来获取time.struct\u time:

In [70]: import datetime as dt

In [71]: dt.datetime(2000,11,30,0,0,0).timetuple()
Out[71]: time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1)

谢谢:D,你的答案是A!