German umlaut in a string.

Discussion in 'Python' started by Lukas Kasprowicz, Aug 12, 2003.

  1. 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)
     
    Lukas Kasprowicz, Aug 12, 2003
    #1
    1. Advertising

  2. 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)
     
    Lukas Kasprowicz, Aug 12, 2003
    #2
    1. Advertising

  3. I tried:

    # _*_ coding: latin1 _*_


    but this doesn?t work too.
     
    Lukas Kasprowicz, Aug 13, 2003
    #3
  4. Lukas Kasprowicz wrote:
    > I tried:
    >
    > # _*_ coding: latin1 _*_
    >
    >
    > but this doesn?t work too.


    Try

    # -*- coding: latin1 -*-

    instead

    --Irmen
     
    Irmen de Jong, Aug 14, 2003
    #4
  5. Lukas Kasprowicz <> 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
     
    Michael Hudson, Aug 14, 2003
    #5
  6. > > 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
     
    Christopher Boomer, Aug 15, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWFya3VzUG9laGxlcg==?=

    Form Post looses Umlaut

    =?Utf-8?B?TWFya3VzUG9laGxlcg==?=, Jul 25, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    664
    Joerg Jooss
    Jul 26, 2005
  2. Reinier
    Replies:
    1
    Views:
    427
    Craig Deelsnyder
    Mar 31, 2006
  3. Norbert Böschen

    textbox-umlaut-Problem, Windows 2003 server German

    Norbert Böschen, Jul 23, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    154
    Norbert Böschen
    Jul 23, 2003
  4. Dirk Einecke
    Replies:
    8
    Views:
    245
    Dirk Einecke
    Apr 12, 2004
  5. John Butler
    Replies:
    7
    Views:
    193
    John Butler
    May 2, 2008
Loading...

Share This Page