在我的申请中,我正在获得时间投入,其形式是:Values = 12,12,12
。
Now i need to validate it h<24 M<60 S<60
etc. and i want final output in %H:%M:%S
format.
To get this i tried datetime.time().
我曾用<代码>价值 = 12 然后用<代码>12,12,尝试过。
In [1]: import datetime
In [2]: values = 12
In [3]: d = datetime.time(values)
TypeError Traceback (most recent call last)
/mypc/test/<ipython console> in <module>()
TypeError: an integer is required
In [4]: d = datetime.time(int(values))
In [5]: d
Out[5]: datetime.time(12, 0)
In [6]: d.strftime( %H:%M:%S )
Out[6]: 12:00:00
In [7]: s = d.strftime( %H:%M:%S )
In [8]: s
Out[8]: 12:00:00
In [9]: values = 12,12,12
In [10]: d = datetime.time(int(values))
ValueError: invalid literal for int() with base 10: 12,12,12
但它的工作如下。
In [24]: datetime.time(12,12,12).strftime( %H:%M:%S )
Out[24]: 12:12:12
因此,问题是这一时间。 时间()作为星体和<代码>12,12,的输入不能按字母换算。
Is there any other way(otherthan regexp) to do the validation for only Hr:M:S.