Just as a heads up, I don't think any regulars here use the C API. casevh probably does (he wrote a couple of tutorials about the C API*), and he might respond but I'm not sure how often he visits or how closely he keeps up with posts.

I haven't tried it, but I think your second example should work. But it does assume all four parameters are lists. If your function is not exposed directly to an end user but is only called by another Python function that validates the input, then this approach is okay. If not, you might just want to use:

If all four of your arguments have the same length, you might want to first convert them into a list of 4-tuples in Python. Then your C function just needs to accept a single argument. Then loop over the list and parse each tuple with PyArg_ParseTuple. The C code would be easier to write but it may be slower due to the list/tuple create in Python.

Hi, I just checked this. let me test this code and I will paste here how it fares with the c snippet and the test python code code as well.Thanks!I didn't run the examples in your 2nd c api tutorial.I should try that out as well sometime soon.

casevh wrote:I'm still here. I've been quite busy at home and at work.

Does this help?

Try installing the following as python lib. the code below should print few gibberishas sample.d(["324","2","fsdf"])i dont know how to retrieve it as an array of char and print it all out.or return it all out.or again build a tuple/list of strings and print it out.

Also could you tell me how to parse a dictionary to map in c++ and return it back as dict?

lovecodecakes wrote:Try installing the following as python lib. the code below should print few gibberishas sample.d(["324","2","fsdf"])i dont know how to retrieve it as an array of char and print it all out.or return it all out.or again build a tuple/list of strings and print it out.

Also could you tell me how to parse a dictionary to map in c++ and return it back as dict?

It is a standard rule in this forum to post the full error message. For Python code, this usually means including the full text of the exception message. You stated it printed gibberish. Include the text printed to the screen. Format it as a code block so any text alignment isn't lost.

If you want us to run some C code, please make sure it compiles. The code you posted had multiple syntax errors. Also include the setup.py file you used to compile the code.

I fixed the syntax errors in your code and fixed several other errors. There were probably two errors in your printf("%c \n", arg2[i]) statement. The %c format code only prints a single character. From your previous comments, I assume you were trying to print the entire string. arg2[i] probably isn't doing what you expect - you are printing the i-th character of each string. Your gibberish probably started with a "3" (when i is 0), then a NULL character (when i is 1), and then a "d" (when i is 2). If you want to print the first character of each string, you should use printf("%c \n", arg2[0]). If you want to print the entire string, you should use printf("%s \n", arg2).

for (i=0; i < t_seqlen; i++) { arg2 = PyString_AsString(PySequence_Fast_GET_ITEM(tseq, i)); if (!arg2) { PyErr_SetString(PyExc_TypeError, "only strings are supported"); Py_DECREF(tseq); return NULL; } /* arg2 is a pointer to a null-terminated array of characters. It is not an array of pointers. So I don't think you should be trying to index it via "i". If you are trying to print just the first character of the string, then you should use:

If you have more questions, can you explain what is your end goal? Are you trying to interface with an existing C library? Are trying to speed up some Python code?

casevh

First of all, thanks for pointing out that i was using an iterator i to print char value over arg2.(the gibberish)

Im also not used to c++ and its STL.im trying to , as my end, rather than take in inputs as arrays of char, input it as map which c++ allows.it will be processed and returned back to python. yes, speeding it up.because there are a few computations happening over the data.I suppose you dont want me to still include the setup.py and error because you have pointed out the errors correctly and included setup yourself.