Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: remove special characters from line (http://www.velocityreviews.com/forums/t319063-re-remove-special-characters-from-line.html)

Radovan Garabik 07-01-2003 03:14 PM

Re: remove special characters from line
 
Chris Rennert <Chris.Rennert@mdi-oshkosh.com> 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!


All times are GMT. The time now is 07:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57