getting string parameterz in pyd
Robert Amesz
sheershion at mailexpire.com
Sat Nov 24 11:31:49 EST 2001
Ens wrote:
> i have a problem in getting a string parameter with
>
> PyArg_ParseTuple(args, "s", &s) // s is (char*)
>
> length of string is unknown and i want to get
> strings of any length.
Well, the *obvious* answer is to use strlen() from the standard C-
library. However, if the string can contain null-bytes that doesn't
work, and then you *must* do someting like:
PyArg_ParseTuple(args, "s#", &s, &len) // s is (char*), len is int
For more information, and a plethora of other formatting options, read
the format string specification in the Python documentation: chapter
"Extending and Embedding", section 1.7: "Extracting Parameters in
Extension Functions". (I know, you'd expect to find detailed
information like that in the "Python/C API" chapter, but it isn't.)
Robert Amesz
More information about the Python-list
mailing list