How can I import DateTime into a script??
Hi there, I am trying to create an Id based on the time of its creation. since I can not use the Pythons thime module I would like to use a DateTime class. However I stumbled trying to do so. the following code: import DateTime t = DateTime.Time() produces an error Error Type: AttributeError Error Value: Time whereas: from DateTime import Time t = DateTime.Time() produces Error Type: ImportError Error Value: import of "Time" from "DateTime" is unauthorized can anybody tell me how to do it correctly? thanks Robert
At 12:20 11-08-2001 +0200, you wrote:
Hi there, I am trying to create an Id based on the time of its creation. since I can not use the Pythons thime module I would like to use a DateTime class. However I stumbled trying to do so. the following code: import DateTime t = DateTime.Time() produces an error Error Type: AttributeError Error Value: Time whereas: from DateTime import Time = DateTime.Time() produces Error Type: ImportError Error Value: import of "Time" from "DateTime" is unauthorized can anybody tell me how to do it correctly? thanks Robert
Are you trying to do this from FS or from a Zope Python Script ?? Anyways you need to do something like this: DateTime().Time() If you are doing this from Zope you don't need to import the DateTime module - it's there already. Gitte
I am trying to create an Id based on the time of its creation.
since I can not use the Pythons thime module I would like to use a DateTime class.
However I stumbled trying to do so.
the following code:
import DateTime
t = DateTime.Time()
The constructor for DateTime makes a DateTime object of the current time. Try something like:: t = DateTime() If you want the Python 'time' module's floating point seconds-since-epoch format, you can say:: secs = t.timeTime() So of course, you could do something like this to get an id:: id = `int(DateTime().timeTime())` which makes a string our of an int out of a floating point number made from the current time. The string thing may or may not be necessary. --jcc (many types)
participants (3)
-
Gitte Wange -
J. Cameron Cooper -
Robert Rottermann