Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
now()
#1
is there a way to do this


from datetime import datetime as dt
now=dt.now
in one statement?

i tried these and they did not work:


from datetime import datetime.now as now
from datetime.datetime import now
so i am looking for a working alternate.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
I don't think it's possible. now() is a method on an object (class instance) in the module. I don't think you can use Python's import statement to get just a method of a class.
Reply
#3
In one statement, no, in one line, yes:
from datetime import datetime as dt;now=dt.now
But then, to use the value of "now" you have to add more statements, so what is the point?
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#4
the purpose of using it as datetime.now is that its very specific. "now" is not.
Recommended Tutorials:
Reply
#5
Quote:in one statement?
Yeah can hack something together,
but something like this has not so much purpose outside the code golf world.
>>> __import__('datetime').datetime.now()
datetime.datetime(2016, 10, 6, 14, 54, 22, 463219)
Reply
#6
(Oct-06-2016, 09:11 AM)Ofnuts Wrote: from datetime import datetime as dt;now=dt.now
I don't think that this will go through PEP8 safely :D
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
(Oct-06-2016, 05:00 PM)wavic Wrote:
(Oct-06-2016, 09:11 AM)Ofnuts Wrote: from datetime import datetime as dt;now=dt.now
I don't think that this will go through PEP8 safely :D

PEP8 is a guide, not a rule.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#8
Just a joke
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020