HP-UX上的string.encode [英] string.encode on HP-UX

查看:48
本文介绍了HP-UX上的string.encode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HP-UX11i上使用Python-2.3.4,代码如下:


导入语言环境

loc = locale.setlocale(locale.LC_ALL)

print''locale ='',loc

loc = locale.nl_langinfo(locale.CODESET)

print''locale ='' ,loc

print''hello''。encode(loc,''replace'')


产生:


locale = CCCCCC

locale = roman8

Traceback(最近一次调用最后一次):

文件" test_locale.py",line 13,in?

print''hello''。encode(loc,''replace'')

LookupError:未知编码:roman8

[SUSE 9.1上的相同代码不会引发异常]。


我应该能够将nl_langinfo()返回的值传递给

string.encode调用?


类似的代码由wxGlade使用,这个异常阻止它运行




有人知道如何修理他在HP-UX上?


-

Richard Townsend

Using Python-2.3.4 on HP-UX11i, the following code:

import locale
loc = locale.setlocale(locale.LC_ALL)
print ''locale ='', loc
loc = locale.nl_langinfo(locale.CODESET)
print ''locale ='', loc
print ''hello''.encode(loc, ''replace'')

produces:

locale = C C C C C C
locale = roman8
Traceback (most recent call last):
File "test_locale.py", line 13, in ?
print ''hello''.encode(loc, ''replace'')
LookupError: unknown encoding: roman8
[The same code on SUSE 9.1 doesn''t raise an exception].

Should I be able to pass the value returned by nl_langinfo() to the
string.encode call?

Similar code is used by wxGlade and this exception prevents it from
running.

Does anybody know how to fix this on HP-UX?

--
Richard Townsend

推荐答案

Richard Townsend< ri ****** @ edshk.demon.co.uk>写道:
Richard Townsend <ri******@edshk.demon.co.uk> writes:
在HP-UX11i上使用Python-2.3.4,代码如下:

import locale
loc = locale.setlocale(locale .LC_ALL)
print''locale ='',loc
loc = locale.nl_langinfo(locale.CODESET)
print''locale ='',loc
print''你好''.coding(loc,''replace'')

产生:

locale = CCCCCC
locale = roman8
Traceback(最新版)最后调用):
文件test_locale.py,第13行,在?
print''hello''。encode(loc,''replace'')
LookupError:未知编码:roman8

[SUSE 9.1上的相同代码不会引发异常]。

我是否应该能够将nl_langinfo()返回的值传递给
string.encode调用?
Using Python-2.3.4 on HP-UX11i, the following code:

import locale
loc = locale.setlocale(locale.LC_ALL)
print ''locale ='', loc
loc = locale.nl_langinfo(locale.CODESET)
print ''locale ='', loc
print ''hello''.encode(loc, ''replace'')

produces:

locale = C C C C C C
locale = roman8
Traceback (most recent call last):
File "test_locale.py", line 13, in ?
print ''hello''.encode(loc, ''replace'')
LookupError: unknown encoding: roman8
[The same code on SUSE 9.1 doesn''t raise an exception].

Should I be able to pass the value returned by nl_langinfo() to the
string.encode call?




什么是roman8?如果它是某些特定的hp-ux,我想

解决方案是教Python如何处理它。如果它只是HP的'/ b $ b名称的iso-8859-1或者其他什么,那么这很容易(与

编码.saseases混合)。


如果它是一些自定义编码,找出每个

八位字节映射到并编写一个编解码器的宏指令不可能是不可能的

很难。


我想无论如何都会欢迎补丁。


干杯,

mwh


-

Windows 2000:小牛。同样多的废话。

- Jim的操作系统谱系,asr



What is roman8? If it''s some hp-ux specific thingy, I guess the
solution is to teach Python what to do with it. If it''s just HP''s
name for iso-8859-1 or something then this is easy (mucking with
encodings.aliases).

If it''s some custom encoding, finding out what unicode codepoint each
octet maps to and writing a codec a la macroman can''t be impossibly
hard.

I guess a patch would be welcome either way.

Cheers,
mwh

--
Windows 2000: Smaller cow. Just as much crap.
-- Jim''s pedigree of operating systems, asr


2004年7月21日星期三,Richard Townsend写道:
On Wed, 21 Jul 2004, Richard Townsend wrote:
在HP-UX11i上使用Python-2.3.4,代码如下:

import locale
loc = locale.setlocale(locale。 LC_ALL)
print''locale ='',loc
loc = locale.nl_langinfo(locale.CODESET)
print''locale ='',loc
print''你好''。。encode(loc,''replace'')

产生:

locale = CCCCCC
locale = roman8
Traceback(最近一次电话会议)最后一篇:
文件test_locale.py,第13行,在?
print''hello''。encode(loc,''replace'')
LookupError:未知编码: roman8

[SUSE 9.1上的相同代码不会引发异常]。
Using Python-2.3.4 on HP-UX11i, the following code:

import locale
loc = locale.setlocale(locale.LC_ALL)
print ''locale ='', loc
loc = locale.nl_langinfo(locale.CODESET)
print ''locale ='', loc
print ''hello''.encode(loc, ''replace'')

produces:

locale = C C C C C C
locale = roman8
Traceback (most recent call last):
File "test_locale.py", line 13, in ?
print ''hello''.encode(loc, ''replace'')
LookupError: unknown encoding: roman8

[The same code on SUSE 9.1 doesn''t raise an exception].




我的猜测是roman8是HP-UX' latin_1的版本。设置别名修复

这个:



My guess is roman8 is HP-UX''s version of latin_1. Setting an alias fixes
this:

import encodings
编码。 aliases.aliases [''roman8''] =''latin_1''
''你好''.codes(''roman8'')
import encodings
encodings.aliases.aliases[''roman8'']=''latin_1''
''hello''.encode(''roman8'')



''你好''


您可以将前两行添加到sitecustomize.py文件中,该文件位于Python路径中的某处
(一般〜/ site-packages /或

/usr/local/lib/python2.X/应该有效。


''hello''

You can add those first two lines to a sitecustomize.py file, located
somewhere in your Python path (generally ~/site-packages/ or
/usr/local/lib/python2.X/ should work).


Christopher T King< sq ****** @ WPI.EDU>写道:
Christopher T King <sq******@WPI.EDU> writes:
我的猜测是roman8是HP-UX的latin_1版本。设置别名修复
这个:
My guess is roman8 is HP-UX''s version of latin_1. Setting an alias fixes
this:




否,HP Roman-8 *与拉丁文1(ISO 8859-1)不同*。您可以在
找到一张桌子,例如< http://www.kostis.net/charsets/hproman8.htm>。


-

Michael Piotrowski,MA< mx*@dynalabs.de>

公钥在< http://www.dynalabs.de/mxp/pubkey.txt>



No, HP Roman-8 is *not* the same as Latin 1 (ISO 8859-1). You can
find a table at, e.g., <http://www.kostis.net/charsets/hproman8.htm>.

--
Michael Piotrowski, M.A. <mx*@dynalabs.de>
Public key at <http://www.dynalabs.de/mxp/pubkey.txt>


这篇关于HP-UX上的string.encode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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