Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12453
| Date | 2011-08-30 22:49 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: Usage of PyDateTime_FromTimestamp |
| References | <j3jhvm$8o8$1@dough.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.586.1314740949.27778.python-list@python.org> (permalink) |
On 30/08/2011 21:42, Andreas wrote:
> Hi,
>
> I'm working on a c-extension of python and want to create an instance of
> python datetime object with a unix timestamp in c.
>
> On the documentation site ( http://docs.python.org/c-api/datetime.html )
> I found the function PyDateTime_FromTimestamp() which returns a new
> reference based on an input parameter.
>
> The description is as follows: Create and return a new datetime.datetime
> object given an argument tuple suitable for passing to
> datetime.datetime.fromtimestamp().
>
> I tried out to call the function with a PyFloat_Object but the function
> always returns NULL (even if I simply put in 0).
>
> Does somebody have an example how I have to call the function or can
> give a hint what kind of parameter tuple is required to get it work?
>
The key phrase is "argument tuple". The arguments passed to a Python
call are always a tuple, not PyFloat_Object.
You can build a tuple from the PyFloat_Object using:
Py_BuildValue("(O)", float_object)
The "(O)" says to build a tuple ("(...)") containing a single object
("O").
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Usage of PyDateTime_FromTimestamp MRAB <python@mrabarnett.plus.com> - 2011-08-30 22:49 +0100
csiph-web