![]() |
now() - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: now() (/thread-337.html) |
now() - Skaperen - Oct-06-2016 is there a way to do this from datetime import datetime as dt now=dt.nowin one statement? i tried these and they did not work: from datetime import datetime.now as now from datetime.datetime import nowso i am looking for a working alternate. RE: now() - micseydel - Oct-06-2016 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. RE: now() - Ofnuts - Oct-06-2016 In one statement, no, in one line, yes: from datetime import datetime as dt;now=dt.nowBut then, to use the value of "now" you have to add more statements, so what is the point? RE: now() - metulburr - Oct-06-2016 the purpose of using it as datetime.now is that its very specific. "now" is not. RE: now() - snippsat - Oct-06-2016 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) RE: now() - wavic - Oct-06-2016 (Oct-06-2016, 09:11 AM)Ofnuts Wrote: from datetime import datetime as dt;now=dt.nowI don't think that this will go through PEP8 safely :D RE: now() - Ofnuts - Oct-06-2016 (Oct-06-2016, 05:00 PM)wavic Wrote:(Oct-06-2016, 09:11 AM)Ofnuts Wrote: from datetime import datetime as dt;now=dt.nowI don't think that this will go through PEP8 safely :D PEP8 is a guide, not a rule. RE: now() - wavic - Oct-06-2016 Just a joke |