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; Py_UNICODE *u; 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) K -----Original Message----- From: python-dev-bounces+kristjan=ccpgames....@python.org [mailto:python-dev-bounces+kristjan=ccpgames....@python.org] On Behalf Of Ulrich Eckhardt Sent: 2. janúar 2009 11:33 To: python-dev@python.org Subject: [Python-Dev] ParseTuple question Hi! 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? Thanks! Uli _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/kristjan%40ccpgames.com _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com