Python论坛  - 讨论区

标题:[python-chinese] sys设置系统缺省编码的问题

2006年03月14日 星期二 20:39

wu wunc superwunc at gmail.com
Tue Mar 14 20:39:18 HKT 2006

在Dive Into Python 中9.2Unicode
提到了这个方法
1)sys.getdefaultencoding()
2)sys.setdefaultencoding('iso-8859-1')
第一个方法好用
执行第二个
>>> import sys
>>> sys.setdefaultencoding('iso-8859-1')
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'module' object has no attribute 'setdefaultencoding'
>>>
但python文档中sys有setdefaultencoding()方法?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060314/e76387ec/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月14日 星期二 21:35

limodou limodou at gmail.com
Tue Mar 14 21:35:51 HKT 2006

On 3/14/06, wu wunc <superwunc at gmail.com> wrote:
> 在Dive Into Python 中9.2Unicode
> 提到了这个方法
> 1)sys.getdefaultencoding()
> 2)sys.setdefaultencoding('iso-8859-1')
> 第一个方法好用
> 执行第二个
> >>> import sys
> >>> sys.setdefaultencoding('iso-8859-1')
> Traceback (most recent call last):
>   File "", line 1, in ?
> AttributeError: 'module' object has no attribute 'setdefaultencoding'
> >>>
> 但python文档中sys有setdefaultencoding()方法?
>

python在启动时会自动执行site.py这个程序,然后会自动将sys.setdefaultencoding这个方法删除。因此你可以通过reload(sys),然后就可以使用了。

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月15日 星期三 09:36

Slowness Chen chenzh at bhh.com.cn
Wed Mar 15 09:36:02 HKT 2006

in my cases(all unicode operations),I haven't seen the need of using 
setdefaultencoding.
but if there were use cases one must use setdefaultencoding, I 'd like to 
know.

----- Original Message ----- 
From: "limodou" <limodou at gmail.com>
To: <python-chinese at lists.python.cn>
Sent: Tuesday, March 14, 2006 9:35 PM
Subject: Re: [python-chinese] sys设置系统缺省编码的问题


> On 3/14/06, wu wunc <superwunc at gmail.com> wrote:
>> 在Dive Into Python 中9.2Unicode
>> 提到了这个方法
>> 1)sys.getdefaultencoding()
>> 2)sys.setdefaultencoding('iso-8859-1')
>> 第一个方法好用
>> 执行第二个
>> >>> import sys
>> >>> sys.setdefaultencoding('iso-8859-1')
>> Traceback (most recent call last):
>>   File "", line 1, in ?
>> AttributeError: 'module' object has no attribute 'setdefaultencoding'
>> >>>
>> 但python文档中sys有setdefaultencoding()方法?
>>
>
> python在启动时会自动执行site.py这个程序,然后会自动将sys.setdefaultencoding这个方法删除。因此你可以通过reload(sys),然后就可以使用了。
>
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>


--------------------------------------------------------------------------------


> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese 


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月15日 星期三 16:36

笨笨狗 chen.ruijie at gmail.com
Wed Mar 15 16:36:30 HKT 2006

在06-3-15,Slowness Chen <chenzh at bhh.com.cn> 写道:

> in my cases(all unicode operations),I haven't seen the need of using
> setdefaultencoding.
> but if there were use cases one must use setdefaultencoding, I 'd like to
> know.


这个我也想知道



--
云电清华同方小民工
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060315/07b96e60/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月15日 星期三 17:27

limodou limodou at gmail.com
Wed Mar 15 17:27:45 HKT 2006

On 3/15/06, 笨笨狗 <chen.ruijie at gmail.com> wrote:
> 在06-3-15,Slowness Chen <chenzh at bhh.com.cn> 写道:
> > in my cases(all unicode operations),I haven't seen the need of using
> > setdefaultencoding.
> > but if there were use cases one must use setdefaultencoding, I 'd like to
> > know.
>
>
> 这个我也想知道
>

在我以前写的 confbot 程序中就用到了这一技巧,不过我忘了为什么这样用了。


--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月15日 星期三 17:42

fla liu fla.liu at gmail.com
Wed Mar 15 17:42:11 HKT 2006

建立一个文件 sitecustomize.py 放在你的 site-package里面
然后 import 就可以了
----------------------------
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Create Time :  2006-2-20 20:42:50

import sys
sys.setdefaultencoding('utf-8')
# 'utf-8' 是你需要的编码
--------------------------------------

On 3/15/06, limodou <limodou at gmail.com> wrote:
> On 3/15/06, 笨笨狗 <chen.ruijie at gmail.com> wrote:
> > 在06-3-15,Slowness Chen <chenzh at bhh.com.cn> 写道:
> > > in my cases(all unicode operations),I haven't seen the need of using
> > > setdefaultencoding.
> > > but if there were use cases one must use setdefaultencoding, I 'd like to
> > > know.
> >
> >
> > 这个我也想知道
> >
>
> 在我以前写的 confbot 程序中就用到了这一技巧,不过我忘了为什么这样用了。
>
>
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月16日 星期四 01:43

Eric dai daibaoming at gmail.com
Thu Mar 16 01:43:58 HKT 2006

http://www.cheetahtemplate.org/whouses.html
----- Original Message ----- 
From: "limodou" <limodou at gmail.com>
To: <python-chinese at lists.python.cn>
Sent: Wednesday, March 15, 2006 5:27 PM
Subject: Re: [python-chinese] sys设置系统缺省编码的问题


> On 3/15/06, 笨笨狗 <chen.ruijie at gmail.com> wrote:
>> 在06-3-15,Slowness Chen <chenzh at bhh.com.cn> 写道:
>> > in my cases(all unicode operations),I haven't seen the need of using
>> > setdefaultencoding.
>> > but if there were use cases one must use setdefaultencoding, I 'd like to
>> > know.
>>
>>
>> 这个我也想知道
>>
> 
> 在我以前写的 confbot 程序中就用到了这一技巧,不过我忘了为什么这样用了。
> 
> 
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>


--------------------------------------------------------------------------------


> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月16日 星期四 09:37

Slowness Chen chenzh at bhh.com.cn
Thu Mar 16 09:37:33 HKT 2006

-1,
that may break third-party libraries and your program's portability
----- Original Message ----- 
From: "fla liu" <fla.liu at gmail.com>
To: <python-chinese at lists.python.cn>
Sent: Wednesday, March 15, 2006 5:42 PM
Subject: Re: [python-chinese] sys设置系统缺省编码的问题


> 建立一个文件 sitecustomize.py 放在你的 site-package里面
> 然后 import 就可以了
> ----------------------------
> #!/usr/bin/python
> # -*- coding: utf-8 -*-
> # Create Time :  2006-2-20 20:42:50
>
> import sys
> sys.setdefaultencoding('utf-8')
> # 'utf-8' 是你需要的编码
> --------------------------------------
>
> On 3/15/06, limodou <limodou at gmail.com> wrote:
>> On 3/15/06, 笨笨狗 <chen.ruijie at gmail.com> wrote:
>> > 在06-3-15,Slowness Chen <chenzh at bhh.com.cn> 写道:
>> > > in my cases(all unicode operations),I haven't seen the need of using
>> > > setdefaultencoding.
>> > > but if there were use cases one must use setdefaultencoding, I 'd 
>> > > like to
>> > > know.
>> >
>> >
>> > 这个我也想知道
>> >
>>
>> 在我以前写的 confbot 程序中就用到了这一技巧,不过我忘了为什么这样用了。
>>
>>
>> --
>> I like python!
>> My Blog: http://www.donews.net/limodou
>> NewEdit Maillist: http://groups.google.com/group/NewEdit
>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese at lists.python.cn
>> Subscribe: send subscribe to python-chinese-request at lists.python.cn
>> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>
>>
>


--------------------------------------------------------------------------------


> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese 


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号