gpt4 book ai didi

datetime - 导入错误: cannot import name 'strftime'

转载 作者:行者123 更新时间:2023-12-02 19:14:12 25 4
gpt4 key购买 nike

我收到错误,不知道为什么,我的代码如下:

year1 = int(input('choose a year :',))
month1 = int(input('choose a month :',))
day1 = int(input('choose a day :',))
year2 = int(input('choose a year :',))
month2 = int(input('choose a month :',))
day2 = int(input('choose a day :',))
from datetime import date, timedelta as td
from datetime import strftime as st
d1 = date(year1, month1, day1)
d2 = date(year2, month2, day2)
delta = d2 - d1
for i in range(delta.days + 1):
day = st((d1 + td(days=i)))
print(get_exrates(day))

我得到的完整错误代码是:

Traceback (most recent call last):
line 17, in <module>
from datetime import strftime as st
ImportError: cannot import name 'strftime'

最佳答案

strftimedatetime 类的实例方法,您需要先从 datetime 模块导入 datetime,然后使用其 strftime 方法:

>>> from datetime import datetime
>>> datetime.strftime
<method 'strftime' of 'datetime.date' objects>

关于datetime - 导入错误: cannot import name 'strftime' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29698162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com