[pypy-dev] Print unicode strings in RPython?

Maciej Fijalkowski fijall at gmail.com
Tue Nov 26 23:22:25 CET 2013


On Mon, Nov 25, 2013 at 11:51 PM, Ryan Gonzalez <rymg19 at gmail.com> wrote:
> Hello,
>
> I'm writing an app in RPython. Whenever I try and print a unicode string,
> the compiled application will crash with a UnicodeEncodingError. Here is an
> example:
>
> def entry_point(argv):
>     print u'\u2502'
>     return 0
>
> def target(driver, args):
>     return entry_point, None
>
> When running it, I get this:
>
> RPython traceback:
>   File "implement.c", line 164, in entry_point
>   File "rpython_rtyper_lltypesystem_rstr.c", line 190, in
> ll_str__UnicodeR_Ptr_GcStruct_rpy_unic_rpy_unico
> Fatal RPython error: UnicodeEncodeError
> Aborted (core dumped)
>
> Am I missing something? The app runs fine under CPython.
>
> --
> Ryan
> When your hammer is C++, everything begins to look like a thumb.

The answer is that you can't print unicode strings in RPython. We can
consider lifting this limitation, but right now it tries to encode
them as ascii. Maybe print u"xxx".encode("utf-8") is what you want?

Cheers,
fijal


More information about the pypy-dev mailing list