[Python-Dev] ParseTuple question (original) (raw)
Kristján Valur Jónsson kristjan at ccpgames.com
Mon Jan 5 11:41:02 CET 2009
- Previous message: [Python-Dev] ParseTuple question
- Next message: [Python-Dev] Python 3 - Mac Installer?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.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
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 at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/kristjan%40ccpgames.com
- Previous message: [Python-Dev] ParseTuple question
- Next message: [Python-Dev] Python 3 - Mac Installer?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]