Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > What's the reverse of Py_BuildValue("u#" ?

Reply
Thread Tools

What's the reverse of Py_BuildValue("u#" ?

 
 
sndive@gmail.com
Guest
Posts: n/a
 
      01-24-2007
How could I get the pointer to and the length of ucs2 array out of a
PyObject representing
a string? Something that works whether PyObject string is in unicode or
not.

Also could I replace a sequence

if(PyBool_Check(obj)) {
....
}
if(PyString_Check(obj)) { // would this be true for any string
type?
....
}
if(PyFloat_Check(obj)) {
....

with a switch?

Thank you!

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Guest
Posts: n/a
 
      01-24-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) schrieb:
> How could I get the pointer to and the length of ucs2 array out of a
> PyObject representing a string? Something that works whether PyObject
> string is in unicode or not.


You can use PyObject_Unicode(o) to convert the object to Unicode first,
then use PyUnicode_AsUnicode to convert it to a Py_UNICODE array, and
PyUnicode_GetSize to find out what the length is. Notice that this will
be UCS-2 only if Py_UNICODE is 16 bits on your platform. If you really
want UCS-2 always, you need to convert the string again using
PyUnicode_AsEncodedObject, then PyString_AsString to find out what
the UCS-2 bytes are.

Remember to check for errors for all these functions, and remember
to decref the results when you don't need them any longer.

>
> Also could I replace a sequence
>
> if(PyBool_Check(obj)) {
>...
> }
> if(PyString_Check(obj)) { // would this be true for any string
>type?
>...
> }
> if(PyFloat_Check(obj)) {
>...
> with a switch?


Not easily. Also, PyString_Check is true only for the byte string
type (and its subtypes).

Regards,
Martin
 
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
cisco/DNP/SCADA and reverse telnet A. Andrews Cisco 0 01-08-2004 06:32 PM
Reverse engineering an EDIF file? Rastislav Struharik VHDL 8 01-02-2004 01:57 PM
Question on Cisco reverse Subnets James Roper Cisco 2 12-16-2003 10:37 PM
Stacks Queues Reverse Reverse Polish dogbite C++ 4 10-10-2003 05:06 AM
Re: AS5350 reverse telnet Aaron Leonard Cisco 0 07-09-2003 11:49 PM



Advertisments