English 中文(简体)
python, and unicodepinderr
原标题:python, and unicode stderr

我使用匿名管道来抓捕所有 st,然后把 st印成富集,当它使用print时,它会 s,而用多比特的果园,这真是给我道歉。 我如何能够把这些产出转换为单编码?

<> 2010年>:<>>>>>

感谢您的答复,但是,如果在<代码>py_runxxx()上出现错误,那么看来str.encode(> > 仅与xxx() 合作,那么,如果在py_runxxx(>>上出现错误,则由我调整方向的中继器将以多条星号记录这一错误信息,那么就能够以单条码方式产生幻觉? https://stackoverflow.com/questions/1956142/how-to-redirect-stderr-in-python>。 该员额。

我后来尝试了。

问题回答

首先,请记住,Windows console可能无法充分支持统法协会编码。

以下实例将python输出到stderrstdout,使用UTF-8。 如果你想要的话,你可以将其改为其他编码。

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import codecs, sys

reload(sys)
sys.setdefaultencoding( utf-8 )

print sys.getdefaultencoding()

sys.stdout = codecs.getwriter( utf8 )(sys.stdout)
sys.stderr = codecs.getwriter( utf8 )(sys.stderr)

print "This is an Е乂αmp١ȅ testing Unicode support using Arabic, Latin, Cyrillic, Greek, Hebrew and CJK code points."

您可以通过将插图作为统法协会编码(例如:< 编码>u)与Unicode in python合作。 Hello World or by using the encode() methods that all strings have.

www.un.org/Depts/DGACM/index_french.htm

aStringVariable.encode( utf-8 )

utf-16将给你UTF-16,而bcii将把它变成一个老的ASCII阵列。

详情见:

www.un.org/Depts/DGACM/index_spanish.htm

这似乎是一个“C/C++”问题,而不是一个 Python问题。

灰色译员总是通过测试书写,以便穿戴/耳光,而不是单条码(或“全程”)。 它是指使用现行编码(如<代码>sys.getdefaultencoding()的所有单编码数据。

如果你希望作为单条编码数据进入 st/st,你必须使用正确的编码加以编码。

你喜欢的C/C++图书馆肯定会这样做。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...