An error was reported when the python2.7 version got the current time.

answer by yourself, the question is closed: what a pit! I first created a time.py file, which conflicts with the method name of pthon, and then I deleted the file, but he actually generated the time.pyc file himself, so he reported an error no matter how to execute it, but the pyc file could not be seen in the editor, so you have to enter the file management and delete it.

Development environment:
mac
python version: 2.7.10
want to get the current time, code:

-sharp -*- coding: utf-8 -*-
import datetime,time
now = time.strftime("%H")
print (now)

error message:

AttributeError: "module" object has no attribute "struct_time"

looked up a lot of information, but it didn"t work. Later, I installed python3, and then executed it.
but some of my things depend on python2,. I can"t use 3. Have you encountered this problem

?

clipboard.png

Apr.02,2021

may need to set the time zone


looks fine. Install it again clipboard.png


the file name of the new py is written as time.py, and
is coupled with its own method. Delete time.py, and then delete the time.pyc file in file management.
file name should not be repeated with python's own method

.
Menu