Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python上将文本转换为URL语法?_Python_Url - Fatal编程技术网

如何在Python上将文本转换为URL语法?

如何在Python上将文本转换为URL语法?,python,url,Python,Url,我想将Python字符串转换为URL语法 比如说 >>> u'한글'.encode('utf-8') '\xed\x95\x9c\xea\xb8\x80' to '%ed%95%9c%ea%b8%80' 当然,这取决于终端或源文件是UTF-8。“安全”的拼写应该是urllib.quote(u'\ud55c\uae00'.encode('utf-8'))。 >>> import urllib2 >>> urllib2.quote('한글')

我想将Python字符串转换为URL语法

比如说

>>> u'한글'.encode('utf-8')
'\xed\x95\x9c\xea\xb8\x80' to '%ed%95%9c%ea%b8%80'

当然,这取决于终端或源文件是UTF-8。“安全”的拼写应该是
urllib.quote(u'\ud55c\uae00'.encode('utf-8'))
>>> import urllib2
>>> urllib2.quote('한글')
'%ED%95%9C%EA%B8%80'