473,841 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

python3 - the hardest hello world ever ?

Hi,

do I miss something (I do hope so) or is switching to Python3
really hard for Latin1-users?

My simplest hello world script - which uses a few German
umlaut characters - doesn't look very intuitive.
I have to set an internal property (with leading underscore)
for each output file I'm using - right?

#!/usr/local/bin/python3.0
# _*_ coding: latin1 _*_

import sys

# the following call doesn't do the job
# sys.setfilesyst emencoding('lat in1')

# but this ugly one (to be done for each output file)
sys.stdout._enc oding='latin1'

print("Hallo, Süßes Python")
Thanks for any enlightening on that subject,
Helmut.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Oct 14 '08 #1
22 4010
Hi Helmut, All,

do I miss something (I do hope so) or is switching to Python3
really hard for Latin1-users?
It's as complicated as ever -- if you have used unicode strings
in the past (as the 3.0 strings now are always unicode strings).
# sys.setfilesyst emencoding('lat in1')
This cares about the character encoding in filenames, not
in file content.

sys.setdefaulte ncoding('iso-8859-1') # or 'latin1'
would do the job, but only in sitecustomize.p y. After
initializing, the function is no longer available.

And using it in sitecustomize.p y is sort of discouraged.

IMHO the assumptions the typical Python installation makes
about the character encoding used in the system are much too
conservative. E.g. under Windows it should it use
GetLocaleInfo (LOCALE_USER_DE FAULT, LOCALE_IDEFAULT ANSICODEPAGE, ...).

Then a lot of things would work out of the box. Of course
including some methods to shoot yourself in the foot, which
you are prevented from by the current behaviour.
Regards,
Peter
Oct 14 '08 #2
do I miss something (I do hope so) or is switching to Python3
really hard for Latin1-users?
Why do you want to switch? sys.stdout.enco ding should already be
iso-8859-1, if you are a Latin1-user.

Regards,
Martin
Oct 14 '08 #3
Hey Helmut,

Did you try just:

print("Hallo, Süßes Python")

Cheers,
Brian

Helmut Jarausch wrote:
Hi,

do I miss something (I do hope so) or is switching to Python3
really hard for Latin1-users?

My simplest hello world script - which uses a few German
umlaut characters - doesn't look very intuitive.
I have to set an internal property (with leading underscore)
for each output file I'm using - right?

#!/usr/local/bin/python3.0
# _*_ coding: latin1 _*_

import sys

# the following call doesn't do the job
# sys.setfilesyst emencoding('lat in1')

# but this ugly one (to be done for each output file)
sys.stdout._enc oding='latin1'

print("Hallo, Süßes Python")
Thanks for any enlightening on that subject,
Helmut.

Oct 14 '08 #4
Helmut Jarausch <ja******@skyne t.bewrites:
I have to set an internal property (with leading underscore)
for each output file I'm using - right?
If you're referring to the source encoding declaration: No,
underscores have no effect. The specification is at
<URL:http://www.python.org/doc/2.5.2/ref/encodings.html> .
#!/usr/local/bin/python3.0
# _*_ coding: latin1 _*_
I'm not sure why you use underscores in this line. The usual form is
to use a mode line as recognised by Emacs::

# -*- coding: latin1 -*-

or Vim::

# vim: fileencoding=la tin1 :

--
\ “Pinky, are you pondering what I'm pondering?” “I think so, |
`\ Brain, but don't you need a swimming pool to play Marco Polo?” |
_o__) —_Pinky and The Brain_ |
Ben Finney
Oct 14 '08 #5
Martin v. Löwis wrote:
>do I miss something (I do hope so) or is switching to Python3
really hard for Latin1-users?

Why do you want to switch? sys.stdout.enco ding should already be
iso-8859-1, if you are a Latin1-user.
What defines me as latin1-user?

commenting
# sys.stdout._enc oding='latin1'
I get
Traceback (most recent call last):
File "latin1.py" , line 8, in <module>

File "/usr/local/lib/python3.0/io.py", line 1485, in write
b = encoder.encode( s)
File "/usr/local/lib/python3.0/encodings/ascii.py", line 22, in encode
return codecs.ascii_en code(input, self.errors)[0]
UnicodeEncodeEr ror: 'ascii' codec can't encode characters in position 1-2:
ordinal not in range(128)

So my system seems to be an ASCII system?
Thanks,
Helmut

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Oct 15 '08 #6
Ben Finney wrote:
Helmut Jarausch <ja******@skyne t.bewrites:
>I have to set an internal property (with leading underscore)
for each output file I'm using - right?

If you're referring to the source encoding declaration: No,
underscores have no effect. The specification is at
<URL:http://www.python.org/doc/2.5.2/ref/encodings.html> .
>#!/usr/local/bin/python3.0
# _*_ coding: latin1 _*_

I'm not sure why you use underscores in this line. The usual form is
to use a mode line as recognised by Emacs::

# -*- coding: latin1 -*-

or Vim::

# vim: fileencoding=la tin1 :
No, I meant the underscore in sys.stdout._enc oding='latin1'
^

As for the source encoding, I have used the underscore version
which seems to work, as well.

Thanks,
Helmut.
--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Oct 15 '08 #7
Brian Quinlan wrote:
Hey Helmut,

Did you try just:

print("Hallo, Süßes Python")
Yes, but that doesn't work here.
Please see my reply to Martin's reply.

Thanks,
Helmut.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Oct 15 '08 #8
Brian Quinlan wrote:
Hey Helmut,

Did you try just:

print("Hallo, Süßes Python")
Yes, but that doesn't work here.
Please see my reply to Martin's reply.

Thanks,
Helmut.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Oct 15 '08 #9
I would just use UTF-8 and be done with it.

Set your editor to write UTF-8 files, set the correct #coding at your
python script, make sure your terminal supports outputting UTF-8
characters (and your font has the correct glyphs) and everything
should be fine. No trickery required.

Even for Python 2.x, the only extra thing needed was the u"" kind of
strings. No other trickery in sys.stdout required. What platform do
you use?

Orestis
--
or*****@orestis .gr
http://orestis.gr/


On 15 Oct 2008, at 11:12, Helmut Jarausch wrote:
Brian Quinlan wrote:
>Hey Helmut,
Did you try just:
print("Hallo , Süßes Python")

Yes, but that doesn't work here.
Please see my reply to Martin's reply.

Thanks,
Helmut.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
--
http://mail.python.org/mailman/listinfo/python-list
Oct 15 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2190
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
6
4134
by: Matthew | last post by:
How would I go about creating a simple "hello world" program that will run in Unix. I am using MS Visual C++.
8
7612
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
13
2147
by: Todd | last post by:
I am curious of the origins of the "Hello World" program. Who was the first to make this popular? That is, where did it start? I did some Google search and did not find an answer. Was it Kerringan and Richie? I no longer have that book and I don't remember if it was in that ubiquitous C book. It was so long ago.
3
2356
by: lovecreatesbeauty | last post by:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the "hello, world" thing using the name "string-constant". But `ISO/IEC 9899:TC2' does not include this kind of thing in section `A.1.5 Constants'.
4
6294
by: arnuld | last post by:
i am learning C and doing the exercise 1-1 of K&R2, where K&R ask to remove some parts of programme and experiment with error, so here i go: #include <stdio.h> int main () { printf('hello world\n'); }
0
2197
by: C.W.Holeman II | last post by:
As K&R state the hardest part is getting a first instance to work. So I am looking for a "hello, world!" example for adding an additional element to an XHTML file. <html> <head><title>Hello, World</title> <body> <h1>Hello, World</h1> <myHello> <p>My hello.</p>
11
3011
by: cj | last post by:
Perhaps someone knows how to do this. When I open a new ASP.NET web service application in VS 2008, it opens with a simple Hello World web service already written. I want to see this work. Without changing a thing I built the solution and published it to localhost default web site. How can I test it?????
3
2112
by: =?Utf-8?B?QkM=?= | last post by:
Hello, I just created a Hello World webservice in VB2005 (this is my first webservice ever). I ran it in debug mode and the page that came up said Hello World and said to change the webservice namespace from tempuri.org to something else so that the xml file could be created. I did that. Then it said to make a web reference (say what?) The only web reference I was able to make was to the local solution: Local Host. Then in the...
0
9865
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9706
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10667
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10303
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7848
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7025
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5691
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3140
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.