import datetime
time_tuple = (2019, 5, 6, 13, 8, 10)
print(datetime.datetime(time_tuple))
报错:
TypeError: an integer is required (got type tuple)
但是 print(datetime.datetime(2019, 5, 6, 13, 8, 10))完全没问题
1
mxy940127 2019-05-06 13:39:31 +08:00
datetime.datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])
看 api 文档 |
2
nondanee 2019-05-06 13:41:06 +08:00 via Android
print(datetime.datetime(*time_tuple))
|
3
Osk 2019-05-06 13:43:21 +08:00
print(datetime.datetime(time_tuple)) --> print(datetime.datetime(*time_tuple))
|
4
Osk 2019-05-06 13:44:44 +08:00
|
5
Gakho 2019-05-06 15:22:53 +08:00
#2 #3 正解,你应该看一下不定参数的函数是怎么调用的
|
6
KevinBu 2019-05-06 18:34:36 +08:00
datetime.datetime() 第一个参数是 year
你给它一个元组,怎么能不报错 |
8
pkookp8 2019-05-06 18:39:48 +08:00 via Android
报错的给了一个参数,是 tuple
不报错的给了 6 个参数 |
9
Huelse OP |
10
cominghome 2019-05-07 09:40:12 +08:00
这种很明显的报错完全可以自己解决的啊兄弟
|
11
neoblackcap 2019-05-07 11:39:57 +08:00
import datetime
time_tuple = (2019, 5, 6, 13, 8, 10) print(datetime.datetime(*time_tuple)) |