English 中文(简体)
带有假装特征的问题
原标题:Problem encoding accented characters with python

我会遇到麻烦,在使用平线指挥线的URL中穿着装的特性。 减少我的问题。

>>> import urllib
>>> print urllib.urlencode({ foo  : raw_input( >  )})
> áéíóúñ

a. 以马卡指挥线印刷:

foo=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA%C3%B1

但同一代码在窗户指挥线上印刷:

foo=%A0%82%A1%A2%A3%A4

玉米结果正确,其特征按需要加以编码;但在窗户里,我有一席血清。

我猜测问题在于密码特征的窗口,但我没有找到解决办法;如果你能够帮助我,我非常感谢。 提前感谢!

最佳回答

Windows的指挥线在美国Windows使用cp437编码。 您:

>>> import sys
>>> sys.stdin.encoding
 cp437 
>>> print urllib.urlencode({ foo :raw_input( >  ).decode( cp437 ).encode( utf8 )})
> áéíóúñ
foo=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA%C3%B1
问题回答

你可以采用明确的编码,取得一致的结果。

>>> str = u"áéíóúñ"
>>> import urllib
>>> urllib.urlencode({ foo :str.encode( utf-8 )})
 foo=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA%C3%B1 

然而,你们需要首先确保你窒息在单体内,因此,如果它不,则可能需要脱条,如原始-投入(Rtin1 )或原材料(.decode(utf-8 )一样。

我认为,投入的编码取决于青少年的所在地,因此取决于其系统。

EDIT:统一编码(str)也应使用本地编码转换为统一编码,从而成为解决办法。





相关问题
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 ]="...

热门标签