Converting C strings to Python problem

Martin v. Loewis martin at v.loewis.de
Tue Feb 26 12:54:59 EST 2002


"Phil Rittenhouse" <phil.rittenhouse at dspfactory.com> writes:

> I'm trying to pass a path string (eg. "c:\spam\test.exe") from C to python,
> but python is interpreting the string as "c:\spam<tab>est.exe".
> 
> I've run into this problem with converting C strings to Python strings using
> Py_BuildValue().   

Is this specific string appearing literally in your C source code? If
so, I would not be surprised: \t, in C, indicates a tab
character. Write "c:\\spam\\test.exe" instead.

> Should the conversion process convert backslashes in C to double backslashes
> in Python?   What is the recommended method for doing the C string to python
> string conversion?  Does PyString_FromString() behave differently?

If it is what I think it is, the recommend strategy is to write what
you mean, using the C programming language :-)

Regards,
Martin



More information about the Python-list mailing list