Applications Google
Menu principal

Post a Comment On: Only Python

"Unicode headaches ... and a solution"

2 Comments -

1 – 2 of 2
Blogger Unknown said...

Without having looked at the rest of your code, so I might be completely off here, this somehow looks wrong:

result = result.decode(sys.getdefaultencoding()).encode('utf-8')

The reason I say this is that you're decoding and encoding in the same place. Since Python unicode support is so good, it's generally a good idea to decode to unicode any use input you get as early as possible, and to encode only as late as possible when outputting strings. Since you're doing complicated web ui stuff here, so it may be that you're not doing anything with 'result' between input and returning it to the browser, but if you are, the string should have already been decoded by the time it gets to this line. Otherwise this will bite you anytime you try to do anything with the string like simple concatenation.

8:07 AM

Blogger André Roberge said...

This is a good point in general. However, in this case, I take the result straight from an interpreter session and inject it into a web browser. The line of code above is the one step inserted in between.

8:16 AM

Spammers: none shall pass.
You can use some HTML tags, such as <b>, <i>, <a>

Comments on this blog are restricted to team members.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot