On Wed, Aug 25, 2010 at 12:57 PM, Lisandro Dalcin <[email protected]> wrote: > 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.
For one thing, the Python 3 print function is not supported for Python < 2.6 runtime environment. However, the -2 mode will support both the Py2 and Py3 runtimes for the foreseeable future, these flags are just about the input source (in the case that the two have different semantics). - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
