Transform URL string into normal string in python (%20 to space etc)
Is there any way in python to transfrom this-> %CE%B1%CE%BB%20 into this: "αλ " which is its real representation?
Thanks in advance!
python string
add a comment |
Is there any way in python to transfrom this-> %CE%B1%CE%BB%20 into this: "αλ " which is its real representation?
Thanks in advance!
python string
What do you mean by "real representation"?
– Mark Byers
Aug 1 '12 at 22:17
add a comment |
Is there any way in python to transfrom this-> %CE%B1%CE%BB%20 into this: "αλ " which is its real representation?
Thanks in advance!
python string
Is there any way in python to transfrom this-> %CE%B1%CE%BB%20 into this: "αλ " which is its real representation?
Thanks in advance!
python string
python string
asked Aug 1 '12 at 21:48
hytromohytromo
49611545
49611545
What do you mean by "real representation"?
– Mark Byers
Aug 1 '12 at 22:17
add a comment |
What do you mean by "real representation"?
– Mark Byers
Aug 1 '12 at 22:17
What do you mean by "real representation"?
– Mark Byers
Aug 1 '12 at 22:17
What do you mean by "real representation"?
– Mark Byers
Aug 1 '12 at 22:17
add a comment |
3 Answers
3
active
oldest
votes
For python 2:
>>> import urllib2
>>> print urllib2.unquote("%CE%B1%CE%BB%20")
αλ
For python 3:
>>> from urllib.parse import unquote
>>> print(unquote("%CE%B1%CE%BB%20"))
αλ
And here's code that works in all versions:
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
print(unquote("%CE%B1%CE%BB%20"))
19
For Python 3:import urllib.request
urllib.request.unquote(...)
– user136036
Jan 7 '15 at 18:51
add a comment |
There are two encodings in play here. Your string has first been encoded as UTF-8, then each byte has been percent-encoded.
To get the original string back you need to first unquote it, and then decode it:
>>> import urllib
>>> s = '%CE%B1%CE%BB%20'
>>> result = urllib.unquote(s).decode('utf8')
>>> print result
αλ
Note that you need a Unicode enabled console in order to display the value (if you get an error with the print statement, try running it in IDLE).
thanks a lot! decode('utf8') was useless to me, though. unquote(s) did the job!
– hytromo
Aug 1 '12 at 22:03
this does not work.
– Frank
Sep 29 '14 at 23:32
But it does. Just tried it to be on the safe side (IDLE, py2.7)
– Lord_Gestalter
Nov 24 '14 at 8:40
add a comment |
python 3 answer
import urllib
urllib.parse.unquote('/El%20Ni%C3%B1o/')
'/El Niño/'
source
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11768070%2ftransform-url-string-into-normal-string-in-python-20-to-space-etc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
For python 2:
>>> import urllib2
>>> print urllib2.unquote("%CE%B1%CE%BB%20")
αλ
For python 3:
>>> from urllib.parse import unquote
>>> print(unquote("%CE%B1%CE%BB%20"))
αλ
And here's code that works in all versions:
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
print(unquote("%CE%B1%CE%BB%20"))
19
For Python 3:import urllib.request
urllib.request.unquote(...)
– user136036
Jan 7 '15 at 18:51
add a comment |
For python 2:
>>> import urllib2
>>> print urllib2.unquote("%CE%B1%CE%BB%20")
αλ
For python 3:
>>> from urllib.parse import unquote
>>> print(unquote("%CE%B1%CE%BB%20"))
αλ
And here's code that works in all versions:
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
print(unquote("%CE%B1%CE%BB%20"))
19
For Python 3:import urllib.request
urllib.request.unquote(...)
– user136036
Jan 7 '15 at 18:51
add a comment |
For python 2:
>>> import urllib2
>>> print urllib2.unquote("%CE%B1%CE%BB%20")
αλ
For python 3:
>>> from urllib.parse import unquote
>>> print(unquote("%CE%B1%CE%BB%20"))
αλ
And here's code that works in all versions:
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
print(unquote("%CE%B1%CE%BB%20"))
For python 2:
>>> import urllib2
>>> print urllib2.unquote("%CE%B1%CE%BB%20")
αλ
For python 3:
>>> from urllib.parse import unquote
>>> print(unquote("%CE%B1%CE%BB%20"))
αλ
And here's code that works in all versions:
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
print(unquote("%CE%B1%CE%BB%20"))
edited Jan 3 '18 at 6:37


Jaymon
2,73322327
2,73322327
answered Aug 1 '12 at 21:51


Igor ChubinIgor Chubin
37.4k785109
37.4k785109
19
For Python 3:import urllib.request
urllib.request.unquote(...)
– user136036
Jan 7 '15 at 18:51
add a comment |
19
For Python 3:import urllib.request
urllib.request.unquote(...)
– user136036
Jan 7 '15 at 18:51
19
19
For Python 3:
import urllib.request
urllib.request.unquote(...)
– user136036
Jan 7 '15 at 18:51
For Python 3:
import urllib.request
urllib.request.unquote(...)
– user136036
Jan 7 '15 at 18:51
add a comment |
There are two encodings in play here. Your string has first been encoded as UTF-8, then each byte has been percent-encoded.
To get the original string back you need to first unquote it, and then decode it:
>>> import urllib
>>> s = '%CE%B1%CE%BB%20'
>>> result = urllib.unquote(s).decode('utf8')
>>> print result
αλ
Note that you need a Unicode enabled console in order to display the value (if you get an error with the print statement, try running it in IDLE).
thanks a lot! decode('utf8') was useless to me, though. unquote(s) did the job!
– hytromo
Aug 1 '12 at 22:03
this does not work.
– Frank
Sep 29 '14 at 23:32
But it does. Just tried it to be on the safe side (IDLE, py2.7)
– Lord_Gestalter
Nov 24 '14 at 8:40
add a comment |
There are two encodings in play here. Your string has first been encoded as UTF-8, then each byte has been percent-encoded.
To get the original string back you need to first unquote it, and then decode it:
>>> import urllib
>>> s = '%CE%B1%CE%BB%20'
>>> result = urllib.unquote(s).decode('utf8')
>>> print result
αλ
Note that you need a Unicode enabled console in order to display the value (if you get an error with the print statement, try running it in IDLE).
thanks a lot! decode('utf8') was useless to me, though. unquote(s) did the job!
– hytromo
Aug 1 '12 at 22:03
this does not work.
– Frank
Sep 29 '14 at 23:32
But it does. Just tried it to be on the safe side (IDLE, py2.7)
– Lord_Gestalter
Nov 24 '14 at 8:40
add a comment |
There are two encodings in play here. Your string has first been encoded as UTF-8, then each byte has been percent-encoded.
To get the original string back you need to first unquote it, and then decode it:
>>> import urllib
>>> s = '%CE%B1%CE%BB%20'
>>> result = urllib.unquote(s).decode('utf8')
>>> print result
αλ
Note that you need a Unicode enabled console in order to display the value (if you get an error with the print statement, try running it in IDLE).
There are two encodings in play here. Your string has first been encoded as UTF-8, then each byte has been percent-encoded.
To get the original string back you need to first unquote it, and then decode it:
>>> import urllib
>>> s = '%CE%B1%CE%BB%20'
>>> result = urllib.unquote(s).decode('utf8')
>>> print result
αλ
Note that you need a Unicode enabled console in order to display the value (if you get an error with the print statement, try running it in IDLE).
answered Aug 1 '12 at 21:52
Mark ByersMark Byers
595k12613631344
595k12613631344
thanks a lot! decode('utf8') was useless to me, though. unquote(s) did the job!
– hytromo
Aug 1 '12 at 22:03
this does not work.
– Frank
Sep 29 '14 at 23:32
But it does. Just tried it to be on the safe side (IDLE, py2.7)
– Lord_Gestalter
Nov 24 '14 at 8:40
add a comment |
thanks a lot! decode('utf8') was useless to me, though. unquote(s) did the job!
– hytromo
Aug 1 '12 at 22:03
this does not work.
– Frank
Sep 29 '14 at 23:32
But it does. Just tried it to be on the safe side (IDLE, py2.7)
– Lord_Gestalter
Nov 24 '14 at 8:40
thanks a lot! decode('utf8') was useless to me, though. unquote(s) did the job!
– hytromo
Aug 1 '12 at 22:03
thanks a lot! decode('utf8') was useless to me, though. unquote(s) did the job!
– hytromo
Aug 1 '12 at 22:03
this does not work.
– Frank
Sep 29 '14 at 23:32
this does not work.
– Frank
Sep 29 '14 at 23:32
But it does. Just tried it to be on the safe side (IDLE, py2.7)
– Lord_Gestalter
Nov 24 '14 at 8:40
But it does. Just tried it to be on the safe side (IDLE, py2.7)
– Lord_Gestalter
Nov 24 '14 at 8:40
add a comment |
python 3 answer
import urllib
urllib.parse.unquote('/El%20Ni%C3%B1o/')
'/El Niño/'
source
add a comment |
python 3 answer
import urllib
urllib.parse.unquote('/El%20Ni%C3%B1o/')
'/El Niño/'
source
add a comment |
python 3 answer
import urllib
urllib.parse.unquote('/El%20Ni%C3%B1o/')
'/El Niño/'
source
python 3 answer
import urllib
urllib.parse.unquote('/El%20Ni%C3%B1o/')
'/El Niño/'
source
edited Jan 1 at 19:17
Ehsan
308212
308212
answered Jun 26 '18 at 19:16
olmergolmerg
34225
34225
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11768070%2ftransform-url-string-into-normal-string-in-python-20-to-space-etc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you mean by "real representation"?
– Mark Byers
Aug 1 '12 at 22:17