Can Python write foreign characters to the console?

B

Bock

I was just told about Python. My searching and reading over the net
I was able to learn that Python can handle "foreign" characters via
Unicodes.

Can or does Python write unicode to the screen?
For example, in c++ cout >> "Hello World." would send this string to the
screen/monitor.

I want to find a programming language that can write German üßäö as
screen output?

Most programming languages/operating systems in North America limit one
to the 127 characters
of ascii.

Thank you for any explanation/direction.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Bock said:
I was just told about Python. My searching and reading over the net
I was able to learn that Python can handle "foreign" characters via
Unicodes.

Can or does Python write unicode to the screen?

Yes. Just do

# -*- coding: iso-8859-1 -*-
print u"Martin v. Löwis"

in a Python script, and it should work.

If it doesn't, you should tell us what operating system and
what console program you are using.

Regards,
Martin
 
D

Do Re Mi chel La Si Do

Hi!

On windows, you MUST also configure the console.

Use CHCP for to force the good code-page.
And, right-click + property + font, for to choice the good font.

With that, I can visu french accents, cyrillic, etc.


@-salutations

Michel Claveau
 
G

Grant Edwards

I was just told about Python. My searching and reading over the net
I was able to learn that Python can handle "foreign" characters via
Unicodes.

Can or does Python write unicode to the screen?
Sure.

For example, in c++ cout >> "Hello World." would send this
string to the screen/monitor.

I want to find a programming language that can write German
üßäö as screen output?

All of the languages I've ever used could write unicode to a
console. Whether your console understands Unicode and displays
it properly is another question.
Most programming languages/operating systems in North America
limit one to the 127 characters of ascii.

If that's true, then you're using crap for an OS.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Do said:
On windows, you MUST also configure the console.

That's not true. In the standard configuration, all characters
from the OEM code page will print fine.

Regards,
Martin
 
D

Do Re Mi chel La Si Do

Hi!

That depends on what we call "console".

Python console?
or
Windows console?

@-salutations

Michel Claveau
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Do said:
That depends on what we call "console".

Python console?
or
Windows console?

AFAICT, it works in both: if I start Python 2.4 (command line)
from the start menu, and have it import a module that prints

# -*- coding: iso-8859-1 -*-
print u"Martin v. Löwis"

it will print the umlaut, and the same happends if I start
cmd.exe, run python, and then run the code that makes that
print statement. In either case, the font selected was
"Raster Fonts", and in cmd.exe, the Active code page was
850.

Regards,
Martin
 
M

Michel Claveau

Hi!

I have a problem, under win-XP, with this code :

# -*- coding: cp-1252 -*-

import sys
print u"Martin v. Löwis"
print "¤ for Noël"
print u"¤ for Noël"
sys.exit()

==> "Python a provoqué une erreur"


Am I the only one to have that?

Michel Claveau
 
?

=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=

Michel said:
Hi!

I have a problem, under win-XP, with this code :

# -*- coding: cp-1252 -*-

import sys
print u"Martin v. Löwis"
print "¤ for Noël"
print u"¤ for Noël"
sys.exit()

==> "Python a provoqué une erreur"


Am I the only one to have that?

No. I get multiple errors with that code:

1. cp-1252 isn't defined. I had to use either cp1252,
or windows-1252.
2. If I correct that, I still get

Martin v. Löwis
Ç for NoÙl
Traceback (most recent call last):
File "xxx.py", line 6, in ?
print u"Ç for NoÙl"
File "C:\Python24\lib\encodings\cp850.py", line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac' in
position 0: character maps to <undefined>

This is not surprising: the first print statement works fine.
The second print statement interprets the CP 1252 in the terminal's
code page, which gives bogus results.
The third command tries the right thing: converting the Unicode
string to the terminal's encoding, CP 850. Now, while the Umlaut (ö)
is supported in CP 850, the EURO SIGN is not, hence the UnicodeError.

Regards,
Martin

P.S. I never get "Python a provoqué une erreur". Not sure where
this message comes from.
 
S

Sibylle Koczian

Martin said:
P.S. I never get "Python a provoqué une erreur". Not sure where
this message comes from.

That's the french equivalent to the german
"python.exe hat ein Problem festgestellt und muss beendet werden."
Coming from Windows, I don't know the english version. I get this if I
don't correct the "coding: cp-1252".

Regards,
Koczian
 

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
474,274
Messages
2,571,366
Members
48,055
Latest member
RacheleCar

Latest Threads

Top