Python
해결법 module 'datetime' has no attribute 'strftime'
악마성
2022. 2. 5. 13:42
728x90
반응형
정말 간단한 time format 을 출력하는 코드인데 너무나도 파이썬은 신기한듯 ㅎ
아무튼 아래와 같은 오류가 발생을 해서 참 난감하고 있는 참이었는데
해결을 해서 이렇게 공유를 한다.
오류 내용
Exception has occurred: AttributeError
module 'datetime' has no attribute 'strftime'
나의 코드
def Logger(self,text):
sdate = datetime.strftime(datetime.date.today, '%Y-%m-%d %H:%M:%S')
sText = f'{sdate} : {text}'
server.slackClient.post_message_to_slack(sText)
print(sText)
여기서 문제가 되는 코드는
sdate = datetime.strftime(datetime.date.today, '%Y-%m-%d %H:%M:%S')
이 부분이었는데 저는 이미 import datetime 을 했는데도 문제가 발생해서 이상했다.
해결법
import datetime
sdate = datetime.datetime.strftime(datetime.datetime.today(), '%Y-%m-%d %H:%M:%S')
print(sdate)
원인은 단순히 호출을할 때 사용하는 () 괄호를 붙히지 않아서 입니다.
728x90
반응형