Extention Module/ list of chars-> string

T

Tuvas

I am currently writing an extention module that needs to recieve a list
of characters that might vary in size from 0 to 8. This is written as a
list of characters rather than a string because it's easier to
manipulate. However, when I pass this list of characters into the
extention module, it keeps giving errors. Is there a way to do one of
the following?

A. Change a list of chars to a single string or
B. Read a list of chars in an extention module

Thanks!
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Tuvas said:
A. Change a list of chars to a single string or
B. Read a list of chars in an extention module

Either is possible, but I recommend to do A:

data = ''.join(data)

Then pass the modified data to the extension module.

Regards,
Martin
 
F

Fredrik Lundh

Tuvas said:
I am currently writing an extention module that needs to recieve a list
of characters that might vary in size from 0 to 8. This is written as a
list of characters rather than a string because it's easier to
manipulate. However, when I pass this list of characters into the
extention module, it keeps giving errors. Is there a way to do one of
the following?

A. Change a list of chars to a single string or

that's easier to do at the python side of things (see martin's reply), but
if you'd rather do
B. Read a list of chars in an extention module

you might find the code on this page somewhat useful:

http://effbot.org/zone/python-capi-sequences.htm

(use PyString_Check, PyString_Size and PyString_AsString to process
the sequence items. see the C API reference for details)

</F>
 
T

Tuvas

Thanks for the help, I actually ended up writing my own simple
charlist2string function, I realized it was only about 4 lines of code,
but, appreciate the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top