Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > German umlaut in a string.

Reply
Thread Tools

German umlaut in a string.

 
 
Lukas Kasprowicz
Guest
Posts: n/a
 
      08-12-2003
Hi Folks,

I have a string filled with much text converted from a tuple.

when I try to do someting like this:

exclusion = re.sub("\\xf6", "%F6", exclusion) #
exclusion = re.sub("\\xfc", "%FC", exclusion) #
exclusion = re.sub("\\xe4", "%E4", exclusion) #
exclusion = re.sub("\\xdf", "%DF", exclusion) #

it takes no effect at the string.

things like:

exclusion = re.sub(',', '', exclusion)
exclusion = re.sub('\(', '', exclusion)
exclusion = re.sub('\)', '', exclusion)
exclusion = re.sub("'", "", exclusion)
exclusion = re.sub(" ", "+%2D", exclusion)
work fine.

when i write the sting in a python console into a variable like:

>>> test = "some\\xf6thing"
>>> print re.sub("\\xf6", "%F6", test)

some%F6thing

I get the correct output.

Why do I can not do a substitute on "\\xf6" or simmilar, but on other I can
do it (like "\(")

I tried with unicode() converting to I think it was from latin-1 to utf-8
and back. with the python console it worked but not with the string that
was converted from tuple before.


greetz Lukas
--
---------------------------------------------------------
Das einzige Mittel gegen Aberglauben ist Wissenschaft.
(Henry Thomas Buckle)
 
Reply With Quote
 
 
 
 
Lukas Kasprowicz
Guest
Posts: n/a
 
      08-12-2003
Hi Leszek,

When I create a string with

<variable>="String"

It works!

But I have a string that was converted from a tuple to a string.
In this case it doesen?t work.
I can substitute everything from the String that was converted from a tuple
except the german umlaut. I take the tuple from a database and i get all
the umlaut from there as "\\x<HEX-CODE-ASCI>"
Changing is NOT possible with "re.sub"

This was my fault...

in the variable "test" i have written in the first tread there is only one
backslash!!!!!!!!!!


greetz Lukasz


Leszek Krupi?ski wrote:
> It works for you?
>
>>>> test = "some\\xf6thing"
>>>> print re.sub("\\xf6", "%F6", test)

> some\xf6thing
>
> (Python 2.3)
>
>>>> exclusion = "some\xf6thing"
>>>> exclusion = re.sub("\\xf6", "%F6", exclusion)
>>>> print exclusion

> some%F6thing
>
> I believe that problem is in slashes.
>
> Leon


--
---------------------------------------------------------
Das einzige Mittel gegen Aberglauben ist Wissenschaft.
(Henry Thomas Buckle)
 
Reply With Quote
 
 
 
 
Lukas Kasprowicz
Guest
Posts: n/a
 
      08-13-2003
I tried:

# _*_ coding: latin1 _*_


but this doesn?t work too.
 
Reply With Quote
 
Irmen de Jong
Guest
Posts: n/a
 
      08-14-2003
Lukas Kasprowicz wrote:
> I tried:
>
> # _*_ coding: latin1 _*_
>
>
> but this doesn?t work too.


Try

# -*- coding: latin1 -*-

instead

--Irmen

 
Reply With Quote
 
Michael Hudson
Guest
Posts: n/a
 
      08-14-2003
Lukas Kasprowicz <(E-Mail Removed)> writes:

> Hi Leszek,
>
> When I create a string with
>
> <variable>="String"
>
> It works!
>
> But I have a string that was converted from a tuple to a string.


Oh, hang on... when you 'str' a tuple, its contents get 'repr'ed, so
you get backslash escapes...


Cheers,
mwh
PS: You want to be using the .replace() string method for things like
this

--
Some people say that a monkey would bang out the complete works
of Shakespeare on a typewriter give an unlimited amount of time.
In the meantime, what they would probably produce is a valid
sendmail configuration file. -- Nicholas Petreley
 
Reply With Quote
 
Christopher Boomer
Guest
Posts: n/a
 
      08-15-2003
> > But I have a string that was converted from a tuple to a string.
> Oh, hang on... when you 'str' a tuple, its contents get 'repr'ed,
> so you get backslash escapes...


> PS: You want to be using the .replace() string method for
> things like this


Would converting the tuple to a string with ",".join(mytuple)
rather than str() work more as he expects in this situation?

Christopher


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help-Charging German Fritzbox from German to English Nigel UK VOIP 4 01-22-2008 10:47 PM
Umlaut in the Params of an ASP.NET page Reinier ASP .Net 1 03-31-2006 04:25 PM
Form Post looses Umlaut =?Utf-8?B?TWFya3VzUG9laGxlcg==?= ASP .Net 7 07-26-2005 07:16 PM
Problem with special characters like (german: umlaut) Dirk Einecke Ruby 8 04-12-2004 04:05 PM
textbox-umlaut-Problem, Windows 2003 server German Norbert Bschen ASP .Net Web Controls 0 07-23-2003 05:23 PM



Advertisments