Reputation: 1658
Hi I tried thousands of encode, decode for this word L'Haÿ-les-Roses . Can somebody help me on how to encode correctly a word with ÿ using python 2.7?
encode("utf-8")
encode("utf-16")
encode("latin-1")
...
Thanks a lot in advance
Upvotes: 0
Views: 1177
Reputation: 20224
What do you want to do with it? To encode it is simple:
a = u"Saint-Rousÿes"
b = a.encode("utf-8")
c = b.decode("utf-8")
print c
# Saint-Rousÿes
But I think it depends on your situation. It doesn't matter how you encode it(surely using supported encoding), you just need to use the same encoding to decode it.
I wrote a minimal test:
import flask
app = flask.Flask(__name__)
@app.route("/")
def test():
return u"L'Haÿ-les-Roses"
app.run()
And I can see L'Haÿ-les-Roses
without any error when I access localhost:5000
. So maybe you should make your question more clearly.
Upvotes: 2
Reputation: 348
Did you make sure to put a declaration at the top of your source file indicating how it is supposed to be read?
# -*- coding:<some encoding> -*-
I believe in this case you would be looking for
# -*- coding: utf-8 -*-
Upvotes: 0