Message89026
Regarding Section "15.15.1.5. Calling functions, continued" on:
http://docs.python.org/3.0/library/ctypes.html
I would recommend changing the first example code block to the following:
>>> printf = libc.printf
>>> printf(b"Hello, %s\n", b"World!")
Hello, World!
14
>>> printf(c_char_p("Hello, %s\n"), c_char_p("World!"))
Hello, World!
14
>>> printf(b"Hello, %S\n", "World!")
Hello, World!
14
>>> printf(c_char_p("Hello, %S\n"), "World!")
Hello, World!
14
>>> printf(c_char_p("%d bottles of beer\n"), 42)
42 bottles of beer
19
>>> printf(c_char_p("%f bottles of beer\n"), 42.5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ctypes.ArgumentError: argument 2: <class 'TypeError'>: Don't know how to
convert parameter 2
And change the second example block to:
>>> printf(c_char_p("An int %d, a double %f\n"), 1234, c_double(3.14))
An int 1234, a double 3.140000
31
Aside: For reference, here is how I started up the interactive session:
mike@www:~$ python3.0
Python 3.0.1 (r301:69556, Jun 6 2009, 21:34:43)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> libc = CDLL("libc.so.6")
Note the "printf.argtypes" method is discussed later in Section
"15.15.1.7. Specifying the required argument types (function
prototypes)", so it might be premature to use it here. |
|
Date |
User |
Action |
Args |
2009-06-07 02:24:05 | mnewman | set | recipients:
+ mnewman, georg.brandl, ggenellina, LambertDW, jwilk |
2009-06-07 02:24:05 | mnewman | set | messageid: <1244341445.23.0.0191996024187.issue4309@psf.upfronthosting.co.za> |
2009-06-07 02:24:01 | mnewman | link | issue4309 messages |
2009-06-07 02:24:01 | mnewman | create | |
|