How to print é as '%C3%A9' in Python 2.7
Question: I want to convert '**é** ' to **%C3%A9** for URI request.

My code is like this:

    
    
    import urllib 
    actor = "Bonnie Erbé"
    

I know that I can manually covert it by

    
    
    print urllib.quote(u"Bonnie Erbé".encode("utf-8")).
    

However, I want to use the variable **actor**.

When I try

    
    
    print urllib.quote(actor)
    

It prints `'Bonnie%20Erb%E9'` not `'Bonnie%20Erb%C3%A9'`.

Thank you.


Answer: Make your program look like this:

    
    
    # encoding: utf-8
    import urllib
    actor = u"Bonnie Erbé"
    
    print urllib.quote(u"Bonnie Erbé".encode("utf-8"))
    
    print urllib.quote(actor.encode('utf-8'))
    

Notice:

1) An `encoding: utf-8` line that says you'll have non-ASCII characters in
your text file.

2) Assigning a unicode string, not a plain string, to the `actor` variable.

3) Encoding `actor` just the same as you encoded the literal string.

