By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,959 Members | 2,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,959 IT Pros & Developers. It's quick & easy.

What happened with python? messed strings?

P: n/a

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)
>>>
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!

--
SDF-EU Public Access UNIX System - http://sdf-eu.org
Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Apr 20, 7:54*pm, <alg...@droog.sdf-eu.orgwrote:
[...]
python should have stayed at version 1.5, every single 'improvement'
has been a mess. But this is the definitive hell.
You can still download Python 1.5.2 from python.org:

http://www.python.org/download/releases/1.5/

HTH

--
Arnaud

Jun 27 '08 #2

P: n/a
En Sun, 20 Apr 2008 15:54:20 -0300, <al****@droog.sdf-eu.orgescribió:
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)
>>>>
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: <http://docs.python.org/dev/howto/unicode.html>
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

--
Gabriel Genellina

Jun 27 '08 #3

P: n/a
al****@droog.sdf-eu.org wrote:
>
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)
>>>>
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...

--
juergen 'pearly' perlinger
"It's hard to make new errors!"
Jun 27 '08 #4

P: n/a
On Apr 20, 11:54*am, <alg...@droog.sdf-eu.orgwrote:
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/whatsn...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.
>
thanks!

--
SDF-EU Public Access UNIX System -http://sdf-eu.org

Jun 27 '08 #5

P: n/a
Juergen Perlinger wrote:
al****@droog.sdf-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.
--
juergen 'pearly' perlinger
"It's hard to make new errors!"
Jun 27 '08 #6

P: n/a
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.
--
juergen 'pearly' perlinger
"It's hard to make new errors!"
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.