What happened with python? messed strings?

G

Guest

Hi,
I used extensively python and now I find this mess with strings,
I can't even reproduce tutorial examples: File "<stdin>", line 0

^
SyntaxError: 'ascii' codec can't decode byte 0xc4 in position 1:
ordinal not in range(128)Is there any good guide to this mess of codecs and hell ?

python should have stayed at version 1.5, every single 'improvement'
has been a mess. But this is the definitive hell.

thanks!
 
G

Gabriel Genellina

I used extensively python and now I find this mess with strings,
I can't even reproduce tutorial examples:
File "<stdin>", line 0
^
SyntaxError: 'ascii' codec can't decode byte 0xc4 in position 1:
ordinal not in range(128)
Is there any good guide to this mess of codecs and hell ?

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
<http://www.joelonsoftware.com/articles/Unicode.html>

Python Unicode Howto: said:
python should have stayed at version 1.5, every single 'improvement'
has been a mess. But this is the definitive hell.

Nobody forces you to use a newer version. You can download 1.5.2 from http://www.python.org/download/releases/1.5
 
J

Juergen Perlinger

Hi,
I used extensively python and now I find this mess with strings,
I can't even reproduce tutorial examples:
File "<stdin>", line 0

^
SyntaxError: 'ascii' codec can't decode byte 0xc4 in position 1:
ordinal not in range(128)
Is there any good guide to this mess of codecs and hell ?

python should have stayed at version 1.5, every single 'improvement'
has been a mess. But this is the definitive hell.

thanks!

Basically you're not using ASCII encoding in your source text... You need to
define an encoding for your source if you're using german umlauts or other
fancy stuff.

See chapter 2.1.4 of the reference manual, and add e.g.

# -*- coding: utf-8 -*-

as first or second line to your script. Make sure your editor talks utf-8,
or use the encoding used by your editor. cp1552 is a good choice for
windows...
 
J

Jason Scheirer

Hi,
I used extensively python and now I find this mess with strings,
I can't even reproduce tutorial examples:>>> "apfel".encode('utf-8')  (it was with umlaut)

  File "<stdin>", line 0

    ^
SyntaxError: 'ascii' codec can't decode byte 0xc4 in position 1:
ordinal not in range(128)

Two things: Mark the character encoding of your file ( read
http://www.python.org/doc/2.3/whatsnew/section-encodings.html ), and
then if that doesn't work try to .decode('something') your string
first with the appropriate codec, then you get a unicode object for
free and you don't need the .encode('utf-8'). Also read the slides at
http://farmdev.com/talks/unicode/ for some good information about
unicode in Python.
Is there any good guide to this mess of codecs and hell ?

python should have stayed at version 1.5, every single 'improvement'
has been a mess. But this is the definitive hell.

It's true -- decorators, the class/type cleanup, properties, -= and
+=, list comprehensions, generators, distutils, and all the new
modules in the standard library are completely, entirely useless.
Python SHOULD have stayed at 1.5.
 
J

Juergen Perlinger

Juergen said:
(e-mail address removed)-eu.org wrote:
[snip]
Basically you're not using ASCII encoding in your source text... You need
to define an encoding for your source if you're using german umlauts or
other fancy stuff.

See chapter 2.1.4 of the reference manual, and add e.g.

# -*- coding: utf-8 -*-

as first or second line to your script. Make sure your editor talks utf-8,
or use the encoding used by your editor. cp1552 is a good choice for
windows...

stupid me. cp1252, of course.
 
J

Juergen Perlinger

Jason Scheirer wrote:
[snip]
It's true -- decorators, the class/type cleanup, properties, -= and
+=, list comprehensions, generators, distutils, and all the new
modules in the standard library are completely, entirely useless.
Python SHOULD have stayed at 1.5.

totally OT, but just a few personal observations:

1. Everything was better a few hundred years ago.

2. A fool with a tool is still a fool.
(just in general, all people present excused...)

3. Simple things tend to become complex. Complex things tend to break, even
when used properly. And it might be hard to use them properly if you don't
have the understanding.

4. Simplicity can be deceptive.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top