Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to convert unicode string to unsigned char *

Reply
Thread Tools

Re: How to convert unicode string to unsigned char *

 
 
Jean-Paul Calderone
Guest
Posts: n/a
 
      05-05-2008
On Mon, 5 May 2008 16:05:08 +0200, Simon Posnjak <(E-Mail Removed)> wrote:
>On Mon, May 5, 2008 at 3:48 PM, Jean-Paul Calderone <(E-Mail Removed)> wrote:
>> On Mon, 5 May 2008 15:41:08 +0200, Simon Posnjak <(E-Mail Removed)> wrote:
>>
>> > Hi!
>> >
>> > I have a C module for which I created a wrapper with swig. The function

>> def is:
>> >
>> > C:
>> >
>> > int some_thing(unsigned char * the_str);
>> >
>> > eg:
>> >
>> > Python:
>> >
>> > some_module.some_thing (the_str)
>> >
>> > Now I would like to feed it with a UTF-8 formatted string:
>> >
>> > test = u'Make \u0633\u0644\u0627\u0645, not war.'
>> >

>>
>> `test´ is not a UTF-8 encoded string. It's a unicode string.
>>
>> To get a UTF-8 encoded string from a unicode string, use the `encode´
>> method:
>>
>> some_module.some_thing(test.encode('utf-8'))

>
>Yes you are correct. It is unicode string. But still if I use encode I
>get the same error:
>
>TypeError with message: in method 'some_thing', argument 1 of type
>'unsigned char *'
>
>So I am looking for a way to "cast" unicode string to unsigned char *.
>


You need to provide some more information about `some_module.some_thing´.
How is it implemented? What Python type does it expect? If it doesn't
take a unicode string and it doesn't take a byte string, I don't know
what kind of string it does take.

Jean-Paul
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
Re: How to convert unicode string to unsigned char * Simon Posnjak Python 1 05-05-2008 04:33 PM
Re: How to convert unicode string to unsigned char * Jean-Paul Calderone Python 0 05-05-2008 01:48 PM
How to convert unicode string to unsigned char * Simon Posnjak Python 0 05-05-2008 01:41 PM



Advertisments