Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: remove special characters from line

Reply
Thread Tools

Re: remove special characters from line

 
 
Egor Bolonev
Guest
Posts: n/a
 
      07-01-2003
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: http://www.velocityreviews.com/forums/(E-Mail Removed) [ru eo en]

 
Reply With Quote
 
 
 
 
Alan Kennedy
Guest
Posts: n/a
 
      07-01-2003
[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
 
Reply With Quote
 
 
 
 
Chris Rennert
Guest
Posts: n/a
 
      07-01-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> [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



 
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
Remove only special characters and junk characters from a file rvino Perl 0 08-14-2007 07:23 AM
Read a file line by line with a maximum number of characters per line Hugo Java 10 10-18-2004 11:42 AM
Re: remove special characters from line Chris Rennert Python 1 07-02-2003 01:05 PM
Re: remove special characters from line Bob Gailer Python 0 07-01-2003 07:22 PM
Re: remove special characters from line Radovan Garabik Python 0 07-01-2003 03:14 PM



Advertisments