472,127 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

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: ni**************@thomas-guettler.de

Aug 1 '07 #1
2 3316
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?

http://www.python.org/dev/peps/pep-3100/#atomic-types

Stefan
Aug 1 '07 #2
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

Aug 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael Weir | last post: by
4 posts views Thread by Guilherme Salgado | last post: by
6 posts views Thread by nico | last post: by
4 posts views Thread by webdev | last post: by
2 posts views Thread by Neil Schemenauer | last post: by
5 posts views Thread by Jamie | last post: by
13 posts views Thread by George Sakkis | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.