On 25 August 2010 16:16, Stefan Behnel <[email protected]> wrote: > Lisandro Dalcin, 25.08.2010 21:00: >> $ cython -3 tmp.pyx >> >> Error converting Pyrex file to C: >> ------------------------------------------------------------ >> ... >> cdef str a = "abc" >> ^ >> ------------------------------------------------------------ >> >> /u/dalcinl/tmp/tmp.pyx:1:13: Cannot convert Unicode string to 'str' >> implicitly. This is not portable and requires explicit encoding. > > Same thing I said before: if you request unicode string literals, you get > unicode literals. >
But in Python 3, the the Python-level 'str' type actually is an unicode string! So, cdef str a = "xyz" should definitely work. If not, once more, writing Cython code that target both Python 2 and 3 runtimes is a PITA. How should I write my code to get a byte string in Py2 and a unicode string in Py3? Yes, I know, for that to make sense the string should be pure ASCII, but that's a pretty common case (e.g. Python 3 stdlib is guaranteed to have all identifiers in the ASCII range) I'm likely missing something... To start: Is Cython -3 generated code supposed to work in a Python 2 runtime? If the answer is yes, I think we should provide mechanisms letting developers use cython -3 but still support Python 2 without too much extra work. -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
