python3 - 有史以来最难的世界? [英] python3 - the hardest hello world ever ?

查看:71
本文介绍了python3 - 有史以来最难的世界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想念一些东西(我希望如此)或者切换到Python3

对于Latin1用户来说真的很难吗?


我最简单的hello world脚本 - 使用一些德语

变音字符 - 看起来不太直观。

我必须为我正在使用的每个输出文件设置一个内部属性(带前导下划线)

- 对吧?


#!/ usr / local / bin / python3.0

#_ * _编码:latin1 _ * _


导入sys


#以下打电话不做这个工作

#sys.setfilesystemencoding(''latin1'')


#但这个丑陋的(要为每个人做输出文件)

sys.stdout._encoding =''latin1''


print(Hallo,Sü?es Python)

感谢您对该主题的任何启发,

Helmut。


-

Helmut Jarausch


Lehrstuhl fuer Numerische Mathematik

RW TH - 亚琛大学

D 52056德国亚琛

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.setfilesystemencoding(''latin1'')

# but this ugly one (to be done for each output file)
sys.stdout._encoding=''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

推荐答案

Hi Helmut,All,
Hi Helmut, All,


我想错过什么(我希望如此)或者切换到Python3

对于Latin1用户来说真的很难吗?
do I miss something (I do hope so) or is switching to Python3
really hard for Latin1-users?



如果你以前使用过unicode字符串

那么复杂(因为现在的3.0字符串是总是unicode字符串)。

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.setfilesystemencoding(''latin1'')
# sys.setfilesystemencoding(''latin1'')



这关心关于文件名中的字符编码,而不是文件内容中的


sys.setdefaultencoding(''iso-8859-1'')#或'' latin1''

可以完成这项工作,但仅限于sitecustomize.py。在

初始化之后,该功能不再可用。


在sitecustomize.py中使用它有点气馁。


恕我直言,典型的Python安装所做的假设

关于系统中使用的字符编码太多了b / b
保守。例如。在Windows下它应该使用

GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_IDEFAULTANSICODEPAGE,...)。


然后很多东西都可以开箱即用。当然

包括一些用脚射击自己的方法,这可以防止当前行为造成你的伤害。

问候,

Peter

This cares about the character encoding in filenames, not
in file content.

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

And using it in sitecustomize.py 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_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, ...).

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


我错过了什么(我希望如此)或者正在切换到Python3
do I miss something (I do hope so) or is switching to Python3

对于Latin1用户来说真的很难吗?
really hard for Latin1-users?



为什么要切换? sys.stdout.encoding应该已经是

iso-8859-1,如果你是Latin1用户的话。


问候,

Martin

Why do you want to switch? sys.stdout.encoding should already be
iso-8859-1, if you are a Latin1-user.

Regards,
Martin


Hey Helmut,


您是否尝试过:


print(Hallo,Sü?es Python)


干杯,

Brian


Helmut Jarausch写道:
Hey Helmut,

Did you try just:

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

Cheers,
Brian

Helmut Jarausch wrote:




我错过了什么(我希望如此)或者转向Python3

对于Latin1用户真的很难?


我最简单的hello world脚本 - 它使用了一些德语

变音字符 - 看起来不太好看非常直观。

我必须为我正在使用的每个输出文件设置一个内部属性(带有前导下划线)

- 对吧?

#!/ usr / local / bin / python3.0

#_ * _ coding:latin1 _ * _


import sys


#以下电话不能完成这项工作

#sys.setfilesystemenc oding(''latin1'')


#但这个丑陋的(要为每个输出文件完成)

sys.stdout._encoding ='' latin1''


print(< Hallo,Sü?es Python")


感谢您对该主题的任何启发,
赫尔穆特。
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.setfilesystemencoding(''latin1'')

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

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



这篇关于python3 - 有史以来最难的世界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆