error when printing a UTF-8 string (python 2.6.2)

Chris Rebert clp2 at rebertia.com
Wed Apr 21 11:37:31 CEST 2010


On Wed, Apr 21, 2010 at 2:29 AM,  <fab at slick.airforce-one.org> wrote:
>> Change your string literals to unicode by adding the u-prefix and you should
>> be OK.
>
> Thanks, it solved the problem... for a while!
>
> I need now to know if s[i] gives the next byte or the next character,
> when I scan the string s. I've googled pages about python and unicode,
> but didn't find a solution to that. I scan the string read from the
> file char by char to construct s, but now get the same error when just
> trying 'print s'.

Assuming s = fichierLaTeX.read() as from your code snippet, the next
character. When in doubt, check what `type(s)` is; if it's <type
'str'>, indices are in bytes; if it's <type 'unicode'>, indices are in
code points.

Please give the full stack traceback for your error.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list