Transform URL string into normal string in python (%20 to space etc)












24















Is there any way in python to transfrom this-> %CE%B1%CE%BB%20 into this: "αλ " which is its real representation?



Thanks in advance!










share|improve this question























  • What do you mean by "real representation"?

    – Mark Byers
    Aug 1 '12 at 22:17
















24















Is there any way in python to transfrom this-> %CE%B1%CE%BB%20 into this: "αλ " which is its real representation?



Thanks in advance!










share|improve this question























  • What do you mean by "real representation"?

    – Mark Byers
    Aug 1 '12 at 22:17














24












24








24


3






Is there any way in python to transfrom this-> %CE%B1%CE%BB%20 into this: "αλ " which is its real representation?



Thanks in advance!










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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












3 Answers
3






active

oldest

votes


















50














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"))





share|improve this answer





















  • 19





    For Python 3: import urllib.request urllib.request.unquote(...)

    – user136036
    Jan 7 '15 at 18:51





















9














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).






share|improve this answer
























  • 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



















1














python 3 answer



import urllib 
urllib.parse.unquote('/El%20Ni%C3%B1o/')

'/El Niño/'


source






share|improve this answer

























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    50














    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"))





    share|improve this answer





















    • 19





      For Python 3: import urllib.request urllib.request.unquote(...)

      – user136036
      Jan 7 '15 at 18:51


















    50














    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"))





    share|improve this answer





















    • 19





      For Python 3: import urllib.request urllib.request.unquote(...)

      – user136036
      Jan 7 '15 at 18:51
















    50












    50








    50







    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"))





    share|improve this answer















    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"))






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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
















    • 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















    9














    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).






    share|improve this answer
























    • 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
















    9














    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).






    share|improve this answer
























    • 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














    9












    9








    9







    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).






    share|improve this answer













    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).







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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



















    • 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











    1














    python 3 answer



    import urllib 
    urllib.parse.unquote('/El%20Ni%C3%B1o/')

    '/El Niño/'


    source






    share|improve this answer






























      1














      python 3 answer



      import urllib 
      urllib.parse.unquote('/El%20Ni%C3%B1o/')

      '/El Niño/'


      source






      share|improve this answer




























        1












        1








        1







        python 3 answer



        import urllib 
        urllib.parse.unquote('/El%20Ni%C3%B1o/')

        '/El Niño/'


        source






        share|improve this answer















        python 3 answer



        import urllib 
        urllib.parse.unquote('/El%20Ni%C3%B1o/')

        '/El Niño/'


        source







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 1 at 19:17









        Ehsan

        308212




        308212










        answered Jun 26 '18 at 19:16









        olmergolmerg

        34225




        34225






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory