For example, I have date_file.py:
import datetime
EPOCH = datetime.datetime.utcfromtimestamp(0)
def date_to_unix(dt):
return (dt - EPOCH).total_seconds() * 1000.0
and I have utils.py:
import date_file
ux = date_file.date_to_unix(datetime.datetime(2020,3,27,0,0,0))
print(ux)
But when I run utils.py it says
"name datetime is not defined"
Isn't it a bit redundant to import these modules everywhere? Is there a better solution for this?
Thanks!
In python you need to import the elements as well. What you did was just import the file itself, but not what is in it.
To import the elements you must use this line in your file utils.py
from date_file import *