force unicode strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Guettler

    #1

    force unicode strings

    Hi,

    is it possible to force all non ascii strings to be unicode strings
    somehow?

    Sometimes I forget that I need to write u'...' if the string contains
    an umlaut. I get an exception in django later. But since the
    exception does not show the string it is hard to find it.

    Is it possible to loop over all strings the interpreter has parsed?

    Pure ascii strings are OK.

    Thomas

    --
    Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/
    E-Mail: guettli (*) thomas-guettler + de
    Spam Catcher: niemand.leerman n@thomas-guettler.de

  • Stefan Behnel

    #2
    Re: force unicode strings

    Thomas Guettler wrote:
    is it possible to force all non ascii strings to be unicode strings
    somehow?
    >
    Sometimes I forget that I need to write u'...' if the string contains
    an umlaut. I get an exception in django later. But since the
    exception does not show the string it is hard to find it.
    I guess you can't afford to wait for Python 3, can you?

    This PEP, previously known as PEP 3000, describes smaller scale changes and new features for which no separate PEP is written yet, all targeted for Python 3000.


    Stefan

    Comment

    • Paul Boddie

      #3
      Re: force unicode strings

      Stefan Behnel wrote:
      >
      I guess you can't afford to wait for Python 3, can you?
      >
      http://www.python.org/dev/peps/pep-3100/#atomic-types
      No need to: just start python with the -U option:

      Python 2.4.1 (#2, Oct 4 2006, 16:53:35)
      [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2.1)] on linux2
      Type "help", "copyright" , "credits" or "license" for more information.
      >>"æøå"
      u'\xe6\xf8\xe5'

      It's just like Jython:

      Jython 2.1 on java1.5.0_03 (JIT: null)
      Type "copyright" , "credits" or "license" for more information.
      >>"æøå"
      '\xE6\xF8\xE5'

      That's a Unicode object, really. Various IronPython users have pointed
      out similar things, too, but this kind of thing has been going on for
      about ten years, I guess.

      Paul

      Comment

      Working...