Re: remove special characters from line

Discussion in 'Python' started by Radovan Garabik, Jul 1, 2003.

  1. Chris Rennert <> wrote:
    > Hello all,
    >
    > If I have a line like this
    >
    > ²blah blah blah blah blah
    >
    > I know I could do a slice like this [1:] to pull everything but the special
    > character, but what if I have several lines in a file.
    > I am not sure how I would detect a special character like that. I would
    > just like to pull everything from those lines (and the special character
    > always appears as the first character, but not on every line) except for the
    > special characters.
    > I hope I have enough detail for someone to help me.
    >
    > Thanks in advance,
    >


    import unicodedata
    def is_special(ch):
    return unicodedata.category(ch)[0]!='L'

    for i in file('filename', 'U'):
    line = unicode(i, 'utf-8') # or your encoding
    if is_special(line[0]):
    line = line[1:]

    or something. Depends on your definiton of "special" :)


    --
    -----------------------------------------------------------
    | Radovan Garabík http://melkor.dnp.fmph.uniba.sk/~garabik/ |
    | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk |
    -----------------------------------------------------------
    Antivirus alert: file .signature infected by signature virus.
    Hi! I'm a signature virus! Copy me into your signature file to help me spread!
    Radovan Garabik, Jul 1, 2003
    #1
    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. Egor Bolonev

    Re: remove special characters from line

    Egor Bolonev, Jul 1, 2003, in forum: Python
    Replies:
    2
    Views:
    535
    Chris Rennert
    Jul 1, 2003
  2. Chris Rennert

    Re: remove special characters from line

    Chris Rennert, Jul 1, 2003, in forum: Python
    Replies:
    1
    Views:
    770
    John Machin
    Jul 2, 2003
  3. Bob Gailer
    Replies:
    0
    Views:
    386
    Bob Gailer
    Jul 1, 2003
  4. rvino
    Replies:
    0
    Views:
    4,636
    rvino
    Aug 14, 2007
  5. Replies:
    8
    Views:
    183
Loading...

Share This Page