Is there conversion method to convert pyunicodeobject to pybyteobject?
Terry Reedy
tjreedy at udel.edu
Tue May 18 12:11:57 EDT 2010
On 5/15/2010 10:50 AM, MathanK wrote:
This is the third time, at least, that you posted this, though the first
time you asked a question. You have given no indication that you
bothered to look in the manual before or between postings.
> A variable whose data type is PyUnicodeObject is to be assigned to
> varioable of PyBytesObject type
>
> example :
>
> PyUnicodeObject *p = ...whatever...;
> function( (PyByteObject*p));
C casting is usually not conversion. It says "pretend that the data is
another type, even though it is not." Only use it when you actually know
what you are doing.
> compiled and got a Bus Error.
In Python, b = p.encode('utf-8') or whatever encoding you want. Look in
the C-API manual for the CPython function that actually does this.
More information about the Python-list
mailing list