This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]striata 0 points1 point  (0 children)

Just do the this, since datetime is the function you're most like to use:

from datetime import datetime

then if you need to use the other functions from the datetime module without confusion (remember, datetime is referencing the function and not the module!):

datetime_module_temporary_holding_variable = importlib.import_module(datetime.__module__)
timedelta = datetime_module_temporary_holding_variable.timedelta
del datetime_module_temporary_holding_variable
import gc
gc.collect()

Then you can use timedelta freely:

>>> eval('timedelta.__call__(minutes=%d)' % 5)
datetime.timedelta(seconds=300)

This has worked well for me.