Re: remove special characters from line

Discussion in 'Python' started by Egor Bolonev, Jul 1, 2003.

  1. Egor Bolonev

    Egor Bolonev Guest

    Hello, Chris!
    You wrote on Tue, 1 Jul 2003 10:03:37 -0500:

    CR> If I have a line like this

    CR> ²blah blah blah blah blah

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

    CR> Thanks in advance,

    I didn't get what you're talkink about.

    With best regards, Egor Bolonev. E-mail: [ru eo en]
     
    Egor Bolonev, Jul 1, 2003
    #1
    1. Advertising

  2. Egor Bolonev

    Alan Kennedy Guest

    [Chris Rennert]

    > 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.


    How about something like this?

    for line in file('myfile.stars'):
    print line.lstrip('*')

    Should remove all '*' (even if there is more than one) from the beginnings (but
    not the ends) of lines.

    Egor Bolonev wrote:

    > I didn't get what you're talkink about.


    Then what was the purpose of your reply?

    I find it helps keeps the signal noise to ratio of the group down if people only
    post when they have something to contribute.

    regards,

    --
    alan kennedy
    -----------------------------------------------------
    check http headers here: http://xhaus.com/headers
    email alan: http://xhaus.com/mailto/alan
     
    Alan Kennedy, Jul 1, 2003
    #2
    1. Advertising

  3. Thanks guys for the help,

    As I was waiting for a reply I was trying a few things as well, this is what
    I ended up doing.
    I created a list with all the valid characters in in and just did a index
    check if(line[0] in LIST):
    That seemed to do exactly what I wanted.
    Again I thank you for the constructive replies Radovan & Alan.

    Chris Rennert
    "Alan Kennedy" <> wrote in message
    news:...
    > [Chris Rennert]
    >
    > > 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.

    >
    > How about something like this?
    >
    > for line in file('myfile.stars'):
    > print line.lstrip('*')
    >
    > Should remove all '*' (even if there is more than one) from the beginnings

    (but
    > not the ends) of lines.
    >
    > Egor Bolonev wrote:
    >
    > > I didn't get what you're talkink about.

    >
    > Then what was the purpose of your reply?
    >
    > I find it helps keeps the signal noise to ratio of the group down if

    people only
    > post when they have something to contribute.
    >
    > regards,
    >
    > --
    > alan kennedy
    > -----------------------------------------------------
    > check http headers here: http://xhaus.com/headers
    > email alan: http://xhaus.com/mailto/alan
     
    Chris Rennert, Jul 1, 2003
    #3
    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. Radovan Garabik

    Re: remove special characters from line

    Radovan Garabik, Jul 1, 2003, in forum: Python
    Replies:
    0
    Views:
    679
    Radovan Garabik
    Jul 1, 2003
  2. Chris Rennert

    Re: remove special characters from line

    Chris Rennert, Jul 1, 2003, in forum: Python
    Replies:
    1
    Views:
    788
    John Machin
    Jul 2, 2003
  3. Bob Gailer
    Replies:
    0
    Views:
    394
    Bob Gailer
    Jul 1, 2003
  4. rvino
    Replies:
    0
    Views:
    4,663
    rvino
    Aug 14, 2007
  5. Replies:
    8
    Views:
    189
Loading...

Share This Page