![](https://secure.gravatar.com/avatar/f1a635b94e00ed23c70bc13d4a8c1043.jpg?s=120&d=mm&r=g)
Hi - I am working on a patch where I have an argument that can either be a unicode string or binary data, I parse the argument using the PyArg_ParseTuple method using the s* format specification and get a Py_Buffer. I now need to convert this Py_Buffer object to a Py_Unicode and pass it into a function. What is the best way to do this? If I determine that the passed argument was binary using another flag parameter then I am passing Py_Buffer->buf as a pointer to the start of the data. This is in winsound module, here's the relevant code snippet sound_playsound(PyObject *s, PyObject *args) { Py_buffer *buffer; int flags; int ok; LPCWSTR pszSound; if (PyArg_ParseTuple(args, "s*i:PlaySound", &buffer, &flags)) { if (flags & SND_ASYNC && flags & SND_MEMORY) { /* Sidestep reference counting headache; unfortunately this also prevent SND_LOOP from memory. */ PyBuffer_Release(buffer); PyErr_SetString(PyExc_RuntimeError, "Cannot play asynchronously from memory"); return NULL; } if(flags & SND_MEMORY) { pszSound = buffer->buf; } else { /* pszSound = ????; */ } -- Sijin