Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should my python web app use unicode for all strings?

I see some frameworks like Django using unicode all over the place so it seems like it might be a good idea.

On the other hand, it seems like a big pain to have all these extra 'u's floating around everywhere.

What will be a problem if I don't do this?

Are there any issues that will come up if I do do this?

I'm using Pylons right now as my framework.

like image 409
Josh Gibson Avatar asked May 05 '09 23:05

Josh Gibson


People also ask

Are all strings in Python Unicode?

Python's string type uses the Unicode Standard for representing characters, which lets Python programs work with all these different possible characters.

Are Python strings ASCII or Unicode?

1. Python 2 uses str type to store bytes and unicode type to store unicode code points. All strings by default are str type — which is bytes~ And Default encoding is ASCII.

Are Python Unicode strings default?

In Python 2, a string is by default a binary string and you need to use u'' to mark a string as a Unicode string. However, in Python 3, a string by default is a Unicode string, and you need to use b'' to explicitly mark a string as a binary string.

Is Unicode the same as string in Python?

Python supports the string type and the unicode type. A string is a sequence of chars while a unicode is a sequence of "pointers".


1 Answers

You can avoid the u'' in python 2.6 by doing:

from __future__ import unicode_literals

That will make 'string literals' to be unicode objects, just like it is in python 3;

like image 51
nosklo Avatar answered Oct 20 '22 01:10

nosklo