Re: remove special characters from line
At 10:03 AM 7/1/2003 -0500, Chris Rennert wrote:
>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
>I hope I have enough detail for someone to help me.
Please define "special character". You have given us one example, but
that's not sufficient to guess your meaning.
One way to do this is to create a string with all acceptable characters,
then see if the first character of each line is in that string.
>>> import string
If you don't want the control characters at the end, use string.printable[:95]
for line in file(filename).readlines():
if line not in string.printable:
... process line
303 442 2625
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.492 / Virus Database: 291 - Release Date: 6/24/2003
|All times are GMT. The time now is 09:50 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.