by Mathnerd314 · 10y ago · 0 comments
For example something like this: https://dateparser.readthedocs.io/en/latest/
Importing packages every time I want to use them is rather tedious though. I guess I need PYTHONSTARTUP as well.
Overall, though, 10 minutes to setup something I only use once or twice a year seems like a waste.
datetime.datetime.strptime("Aug 18 2015", "%b %d %Y")
> datetime.datetime(2015, 8, 18, 0, 0)
Like xapata said, if you import from datetime, it looks "nicer". I prefer to see where things come from most of the time, because I keep open long sessions and it can become messy otherwise.I don't really see how this can take 10 minutes to setup. You can have the import already in a file called dateutils.py and you only set it up once:
import datetime
def string2date(val):
return datetime.datetime.strptime(val, "%b %d %Y")
Then your session becomes easier from dateutils import *
string2date("Jul 4 1776")
datetime.datetime(1776, 7, 4, 0, 0)
However, I think at this point we're talking more about our personal preferences for tools rather than the original subject. It just struck me that your example was something that is available in Python using standard library modules.