蟒蛇。短语表示,如何更改? [英] Python. Phrase representation, how to change?

查看:157
本文介绍了蟒蛇。短语表示,如何更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这个短语中的编码是什么(我想要一个答案)。主要,我想改变我的短语。



例如:


Hello World!成为你好%20世界!%0A



Olámundo!成为 Ol%C3%A1%20mundo !%0A%0A


我想要一个python解决方案。



如果我有


>>> Phrase ='Olámundo!'


如何将其更改为



< >

>>> FinalPhrase



'Ol%C3%A1%使用Python?



Google使用它在您的翻译网站,例如:



请参阅:



http://translate.google.com.br/#en|pt|Hello%20World!% 0A%0A



http://translate.google.com.br/#pt|en|Ol%C3%A1%20mundo!%0A



我需要在Web应用程序中使用它,并使用网址连接到使用这种类型的网址的网站。

解决方案

 >>> import urllib2 
>>>> urllib2.quote
< function quote at 0x104a10848>
>>>> urllib2.quote(ü)
'%C3%BC'
>>>> urllib2.quote('Olámundo!')
'Ol%C3%A1%20mundo%21'


I don't know what's the encoding present in this phrases (and I'd like a answer to this too). Mainly, I'd like change my phrases to it.

For example:

Hello World! becomes Hello%20World!%0A

Olá mundo! becomes Ol%C3%A1%20mundo!%0A%0A

I'd like a python solution for this.

If I have

>>>Phrase='Olá mundo!'

How to change it to

>>>FinalPhrase

'Ol%C3%A1%20mundo!%0A%0A'

using Python?

Google uses it in your translation site, for example:

See:

http://translate.google.com.br/#en|pt|Hello%20World!%0A%0A

http://translate.google.com.br/#pt|en|Ol%C3%A1%20mundo!%0A

I need this use in Web applications and do urls to connect to some sites who uses this type of url.

解决方案

>>> import urllib2
>>> urllib2.quote
<function quote at 0x104a10848>
>>> urllib2.quote("ü")
'%C3%BC'
>>> urllib2.quote('Olá mundo!')
'Ol%C3%A1%20mundo%21'

这篇关于蟒蛇。短语表示,如何更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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