When should I use Unicode string?

django, python, unicode

Solution

IMO you should use Unicode wherever you have text. You never know if Jürgen, Søren or Joël are going to present their œuvre in the context of your application.

When you have data to be transferred to another process or to a file, you should have them as regular string (Py2) resp. `bytes()` object (Py3). In order to identify the interface between these realms, you must be a little careful.

Problem

I reflect when should I use Unicode string in Python 2.7 and my django applications. Is it good habit to use convention `u'some string'` for every string ? For example: ``` // models.py # -*- coding: UTF-8 -*- class ModelClass(models.Model) field_name = models.ForeignKey(SomeModel, related_name=u'some_models') # ... class Meta: ordering = (u'created', u'name',) ``` and ``` // urls.py # -*- coding: UTF-8 -*- urlpatterns = patterns(u'', url(r'^a/$', views.some_view(), name=u'a'), url(r'^b/(?P<pk>[0-9]+)/$', views.some_view2(), name=u'b'), ) ``` ?

Original source

Related problems