[Python-Dev] ParseTuple question

Kristján Valur Jónsson kristjan at ccpgames.com
Mon Jan 5 11:41:02 CET 2009

Funny, I was just looking at this code.
Anyway, whenever I need Unicode stuff as an argument, I use this idiom:
PyObject *uO;
PyObject *uU;
If (!PyArg_ParseTuple(args, "O", &uO)) return 0;
uU = PyUnicode_FromObject(uO);
if (!uU) return 0;
u = PyUnicode_AS_UNICODE(uU);

There is no automatic conversion in PyArg_ParseTuple, because there is no temporary place to store the converted item.  It does work the other way round (turning a Unicode object to a char*) because the Unicode object has a default conversion member slot to store it.
It should be possible to augment the PyArg_ParseTuple to provide a slot for a temporary object, something like:
PyArg_ParseTuple(args, "u", &uU, &u)


-----Original Message-----
From: python-dev-bounces+kristjan=ccpgames.com at python.org [mailto:python-dev-bounces+kristjan=ccpgames.com at python.org] On Behalf Of Ulrich Eckhardt
Sent: 2. janúar 2009 11:33
To: python-dev at python.org
Subject: [Python-Dev] ParseTuple question


I'm looking at NullImporter_init in import.c and especially at the call to 
PyArg_ParseTuple there. What I'm wondering is what that call will do when I 
call the function with a Unicode object. Will it convert the Unicode to a 
char string first, will it return the Unicode object in a certain (default) 
encoding, will it fail?

I'm working on the MS Windows CE port, and I don't have stat() there. Also, I 
don't have GetFileAttributesA(char const*) there, so I need a wchar_t 
(UTF-16) string anyway. What would be the best way to get one?


Python-Dev mailing list
Python-Dev at python.org
Unsubscribe: http://mail.python.org/mailman/options/python-dev/kristjan%40ccpgames.com

More information about the Python-Dev mailing list