Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 from datetime import *
I'm using PyCharm Community 2019.1.4 (July 2019) and Python version 3.7.4, July 8, 2019.
My system is has 32GB RAM and an i9900 CPU running Windows 10 Pro (not sure if any of this matters but don't want someone to ask).

I'm teaching myself Python using the "Python in Easy Steps" book by Mike McGrath. I've had one or two programs that had minor errors and a Google search helped me fix the issues. The program I'm having difficulty with now is as follows (I'm copying the example code exactly as provided:
from datetime import *

today =
print('Today is:', today)

for attr in \
    print('Time:', today.hour,':', today.minute, sep='')
day = today.strftime('%A')
month = today.strftime('%B')

print('Date:',day, month, 
If I only run 'from datetime import *', I get no error so that in itself is not the issue; however, once I add any code such as only the second line, I get the following errors:
Traceback (most recent call last): File "C:/Users/Dr. Nicholas Shaw/PycharmProjects/Practice_2/venv/", line 1, in <module> from datetime import * File "C:\Users\Dr. Nicholas Shaw\PycharmProjects\Practice_2\venv\", line 3, in <module> today = NameError: name 'datetime' is not defined Process finished with exit code 1
I've tried different solutions based upon code found through Google searches such as the 3 line program found here: No matter what I do - same errors. I reviewed what is included in 'datetime' to make sure that the version of Python I'm using has these functions - they do.

In advance - thank you!

buran wrote Aug-15-2019, 09:16 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added the error tags for you.
See BBcode help for more info.
your script is named, thus it shadows the built-in module datetime that you try to import. rename your own file to something different.

by the way star imports are generally discouraged and considered bad practice. read
boring_accountant and scidam like this post
Thank you, buran!! That was it - renamed the file and it worked. And thank you for putting in the output tags; will remember that for next time.

I used the * because that is what the author used in his book. I will review the link you provided.


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str' findbikash 2 288 Sep-18-2019, 08:32 AM
Last Post: buran

Forum Jump:

Users browsing this thread: 1 Guest(s)