[Python-Dev] Unicode strings as filenames

Martin v. Loewis martin@v.loewis.de
Mon, 7 Jan 2002 08:07:05 +0100


> I'm sure that is not what Marc meant.  I think he simply meant a
> conversion function that would return the filename as either byte or
> Unicode.  Get your arg from PyArg_ParseTuple, and convert it with
> this function.

If you have this, how do you know whether to call fopen or wfopen? If
it was a byte string, you need to pass it to fopen; if it was a
Unicode string, you pass it to wfopen.

Maybe that's what MAL meant, but then it won't work.

> Have I missed it all these years, or should we define a PyArg_ParseTuple
> format that takes a "void **" and a function pointer to a type conversion
> function?

This is what O& does. Unless it fills a PyObject*, you have a hard
time telling what it is that you got. It works for the void** case
only if it always fills in the same type (e.g. Py_UNICODE*); filling
int Py_UNICODE* in some cases and char* in others, without telling
you, is useless.

Regards,
Martin