German umlaut in a string.

L

Lukas Kasprowicz

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:
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
 
L

Lukas Kasprowicz

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
 
M

Michael Hudson

Lukas Kasprowicz said:
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
 
C

Christopher Boomer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top