On Sat, Sep 19, 2009 at 1:31 PM, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sat, Sep 19, 2009 at 9:59 AM, Joshua Russo <josh.r.ru...@gmail.com>wrote: > >> I was working through some regression tests and saw a scenario I thought >> wasn't allowed/recommended. I was under the impression that if you specified >> UTF-8 encoding at the top of the file you where not suppose to use u >> decorated unicode static string. So instead of u'prédio' I use 'prédio' in >> files where I specify the encoding in the file. >> Now in regressiontests/admin_views/models.py I see u'¿Chapter?'. Does it >> not matter if I use the u decorator on static strings with the encoding >> specified? I was initially told that it could create problems. >> >> > Someone told you wrong. The encoding declaration is useful specifically > for unicode literals, see: http://www.python.org/dev/peps/pep-0263/. With > the encoding declaration, the Python interpreter can build a unicode object > correctly from the source bytes, since it knows the encoding of the source > bytes. Without the encoding declaration, the interpreter would not know the > encoding of the source bytes, so would be unable (without making some > assumption) to correctly build unicode string objects from unicode literals. > > The encoding declaration does nothing helpful for bytestrings -- they are > still bytestrings, with no known encoding carried around with them. Django > code assumes utf-8 encoding for bytestrings so in many cases where you are > using utf-8 as the encoding you can still use string literals instead of > unicode literals. However there is no advantage to doing so and in fact > using utf-8 string literals can cause problems in other places with code > that assumes another encoding (e.g. ascii) for byte strings. > Ok thanks, good to know --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---