[Tutor] Re: test if file is not ascii
Roger Merchberger
zmerch at 30below.com
Fri Oct 31 14:39:37 EST 2003
At 14:19 10/31/2003 -0500, Paul Tremblay wrote:
[snippety]
>I have tried this code:
>
>for letter in line:
> char = ord(letter)
> if char < 20:
> sys.stderr.write('File contains illegal characters.\n')
> return 101
Checking each individual char [as you noticed] is insane...
... have you tried a regular expression?
Something like:
=-=-=-=-=-=-=-=
import re
bb = 'this is the search string that I want to see is in it...'
if re.search('[\x00-\x19]',bb):
print "Yes it's in there"
else:
Print "No, it's not in there"
=-=-=-=-=-=-=-=
However, I don't know off the top of my head how to specify special
characters in regexps... What I listed might work, but I didn't have a
chance to check. However, I would think it would be faster than a
char-by-char search...
Hope this helps,
Roger "Merch" Merchberger
--
Roger "Merch" Merchberger -- sysadmin, Iceberg Computers
zmerch at 30below.com
What do you do when Life gives you lemons,
and you don't *like* lemonade?????????????
More information about the Tutor
mailing list