There's a question I've been wondering about for the datetime module as if there's a way to import the year function within the same line like:
from datetime.date.today import year
or something along the lines... or it is not possible and I would have to import date then extract the year to from the today function.
CodePudding user response:
Probably to easiest way to do it:
from datetime import date
print(date.today().year)
the "today" function builds a datetime object for you using the current unix time, so you can't import the year without instantiating a new datetime object this way to parse the unix timestamp.
CodePudding user response:
You can only import an object (class, function or a constant)
or a module
or a package
in python.
The year
is an integer data part of return value of today()
function so it cannot be imported.