重装(SYS) [英] reload(sys)

查看:88
本文介绍了重装(SYS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有一个编码问题并通过

" sys.setdefaultencoding(''utf-8'''解决了它)...


我的第一次尝试并不成功,因为当我导入sys模块时,setdefaultencoding没有命名

。之后,我导入sys模块,我需要

write" reload(sys)"还有。


我想知道为什么我们需要调用reload(sys)。得到setdefaultencoding

名为?


快乐编码

解决方案

< blockquote> S?nmez Kartal写道:


我有一个编码问题并通过

" sys.setdefaultencoding( ''utf-8'')" ...


我的第一次尝试并不成功,因为当我导入sys时,setdefaultencoding没有命名

模块。之后,我导入sys模块,我需要

write" reload(sys)"还有。


我想知道为什么我们需要调用reload(sys)。得到setdefaultencoding

命名?



sys.setdefaultencoding是故意从sys模块中删除的,因为你真的不应该使用它来加载
。 reload()调用

恢复已删除的属性。


如果你想要一个不那么脆弱的编码问题解决方案,请解释

问题是什么,这里的人可以帮你找到更好的

解决方案。


STeVe


On 31 A ustos,04:24,Steven Bethard< steven.beth ... @ gmail.comwrote:


S?nmez Kartal写道:


我有编码问题并通过

" sys.setdefaultencoding(''utf-8 '')" ...


我的第一次尝试并不成功,因为setdefaultencoding没有命名

when我导入了sys模块。之后,我导入sys模块,我需要

write" reload(sys)"也。


我想知道为什么我们需要调用reload(sys)得到setdefaultencoding

命名?



sys.setdefaultencoding是故意从sys模块中删除的,因为你真的不应该使用它来加载
。 reload()调用

恢复已删除的属性。


如果你想要一个不那么脆弱的编码问题解决方案,请解释

问题是什么,这里的人可以帮你找到更好的

解决方案。


STeVe



我使用的是XMLBuilder(xmlbuilder.py)。我正在写XML文件为

" f.write(str(xml))"。在执行该行时,它会给出错误的

描述,配置你的默认编码...我的操作系统'

默认为utf-8,而Emacs' '也是utf-8。 XMLBuilder的默认值是

utf-8。在ascii中有一些字符翻译可能无法打印

。我试图替换像(TM)(R)这样的字符...我现在不能记住它们,但如果有必要,我可以很容易地找到它们

.. 。


这是xmlbuilder.py中引发错误的部分。


试试:

if self .pretty:

#tabs是邪恶的,所以我们将使用两个空格

outstr = self._dom.toprettyxml("

" ,encoding = self.encoding)

else:

outstr = self._dom.toxml(encoding = self.encoding)
除了UnicodeDecodeError之外的


sys.stderr.write(''解码错误:你必须配置

默认编码\ n'')

sys.exit( )


我可以做什么而不是import sys; reload(sys);

sys.setdefaultencoding(''utf-8'')"?


快乐编码


2007年8月31日星期五12:53:36 +0000,S ?? nmez Kartal写道:


31一个ustos,04:24,Steven Bethard< steven.beth ... @ gmail.comwrote:


> Snmez Kartal写道:


我有编码问题并通过

" sys.setdefaultencoding(''utf-8'')" ... $解决了b $ b


我的第一次尝试并不成功,因为当我导入sys模块时,setdefaultencoding没有命名为

。之后,我导入sys模块,我需要

write" reload(sys)"也。


我想知道为什么我们需要调用reload(sys)得到setdefaultencoding

命名?


sys_setdefaultencoding是在加载之后故意从sys模块中删除的,因为你真的不应该使用它。 reload()调用
恢复已删除的属性。

如果你想要一个不那么脆弱的编码问题的解决方案,请解释
问题是什么,以及这里的人可以帮助您找到更好的解决方案。



我使用的是XMLBuilder(xmlbuilder.py)。我正在写XML文件为

" f.write(str(xml))"。执行该行时,它会给出错误的

描述,配置你的默认编码...



这对我们没有帮助那么多。什么是`f`这里什么是`xml`?


这是xmlbuilder.py中引发错误的部分。


尝试:

如果self.pretty:

#tabs是邪恶的,所以我们将使用两个空格

outstr = self。 _dom.toprettyxml("

",encoding = self.encoding)

else:

outstr = self._dom.toxml(encoding = self.encoding)

除了UnicodeDecodeError:

sys.stderr.write(''解码错误:你必须配置

默认编码\ n'')

sys.exit()



因此该对象上有一个属性`self.encoding`。它设定好了吗?那是什么

编码呢?你是否把字符串的值超出ASCII

到你的XML或unicode字符串中?


Ciao,

Marc'' BlackJack''Rintsch


Hello,

I''ve had an encoding issue and solved it by
"sys.setdefaultencoding(''utf-8'')"...

My first try wasn''t successful since setdefaultencoding is not named
when I imported sys module. After, I import sys module, I needed to
write "reload(sys)" also.

I wonder why we need to call "reload(sys)" to get setdefaultencoding
named?

Happy coding

解决方案

S?nmez Kartal wrote:

I''ve had an encoding issue and solved it by
"sys.setdefaultencoding(''utf-8'')"...

My first try wasn''t successful since setdefaultencoding is not named
when I imported sys module. After, I import sys module, I needed to
write "reload(sys)" also.

I wonder why we need to call "reload(sys)" to get setdefaultencoding
named?

sys.setdefaultencoding is purposely deleted from the sys module after
it''s loaded because you really shouldn''t be using it. The reload() call
restores the deleted attribute.

If you''d like a less brittle solution to your encoding issue, explain
what the issue was, and people here can probably help you find a better
solution.

STeVe


On 31 A ustos, 04:24, Steven Bethard <steven.beth...@gmail.comwrote:

S?nmez Kartal wrote:

I''ve had an encoding issue and solved it by
"sys.setdefaultencoding(''utf-8'')"...

My first try wasn''t successful since setdefaultencoding is not named
when I imported sys module. After, I import sys module, I needed to
write "reload(sys)" also.

I wonder why we need to call "reload(sys)" to get setdefaultencoding
named?


sys.setdefaultencoding is purposely deleted from the sys module after
it''s loaded because you really shouldn''t be using it. The reload() call
restores the deleted attribute.

If you''d like a less brittle solution to your encoding issue, explain
what the issue was, and people here can probably help you find a better
solution.

STeVe

I was using the XMLBuilder(xmlbuilder.py). I''m writing XML files as
"f.write(str(xml))". At execution of that line, it gives error with
description, configure your default encoding... My operating system''s
default is utf-8, and Emacs'' is utf-8 too. Default of XMLBuilder is
utf-8 too. There were some characters interpreter may couldn''t print
in ascii. I have tried to replace those characters like (TM) (R)... I
cannot remember them right now, but if necessary I can find them
easily...

This is the part of xmlbuilder.py which raises the error.

try:
if self.pretty:
# tabs are evil, so we will use two spaces
outstr = self._dom.toprettyxml("
",encoding=self.encoding)
else:
outstr = self._dom.toxml(encoding=self.encoding)
except UnicodeDecodeError:
sys.stderr.write(''Decoding Error: You must configure
default encoding\n'')
sys.exit()

What I can do instead of "import sys; reload(sys);
sys.setdefaultencoding(''utf-8'')"?

Happy coding


On Fri, 31 Aug 2007 12:53:36 +0000, S??nmez Kartal wrote:

On 31 A ustos, 04:24, Steven Bethard <steven.beth...@gmail.comwrote:

>Snmez Kartal wrote:

I''ve had an encoding issue and solved it by
"sys.setdefaultencoding(''utf-8'')"...

My first try wasn''t successful since setdefaultencoding is not named
when I imported sys module. After, I import sys module, I needed to
write "reload(sys)" also.

I wonder why we need to call "reload(sys)" to get setdefaultencoding
named?


sys.setdefaultencoding is purposely deleted from the sys module after
it''s loaded because you really shouldn''t be using it. The reload() call
restores the deleted attribute.

If you''d like a less brittle solution to your encoding issue, explain
what the issue was, and people here can probably help you find a better
solution.


I was using the XMLBuilder(xmlbuilder.py). I''m writing XML files as
"f.write(str(xml))". At execution of that line, it gives error with
description, configure your default encoding...

This doesn''t help us that much. What is `f` here and what is `xml`?

This is the part of xmlbuilder.py which raises the error.

try:
if self.pretty:
# tabs are evil, so we will use two spaces
outstr = self._dom.toprettyxml("
",encoding=self.encoding)
else:
outstr = self._dom.toxml(encoding=self.encoding)
except UnicodeDecodeError:
sys.stderr.write(''Decoding Error: You must configure
default encoding\n'')
sys.exit()

So there is an attribute `self.encoding` on that object. Is it set? What
encoding is it? And do you put byte strings with values outside ASCII
into your XML or unicode strings?

Ciao,
Marc ''BlackJack'' Rintsch


这篇关于重装(SYS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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