str as param for timedelta
Philipp
philipp.knuesel at gmail.com
Fri Jan 27 05:04:42 EST 2006
Hello Pythonistas
I'm new to Python, I hope you understand my question.
I would like to pass a parameter "gap" to a function. gap should be
used there to create a timedelta Object.
from datetime import *
def f(gap):
print (datetime.now() + datetime.timedelta(gap))
f('hours = -8')
I read in the manual that datetime does accept ints, longs, or floats,
which may be positive or negative. Same as the error message:
"unsupported type for timedelta days component: str"
I found out, that I can pass an Object
def f1(deltaObj):
print (datetime.now() + deltaObj)
f1(timedelta(hours = -8))
I would prefer the first version, as it is easier to use the string for
representation and so on.
Is there any way to pass a string to the function and use it there for
the timedelta?
or you might say I missed some basic concepts...
... in any case, thank you very much!
Phil
More information about the Python-list
mailing list