[Tutor] file.read..... Abort Problem (fwd)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Oct 21 01:14:24 CEST 2005


[Keeping tutor in CC]

---------- Forwarded message ----------
Date: Thu, 20 Oct 2005 23:21:13 +0200
From: Tomas Markus <tomas.markus at gmail.com>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] file.read..... Abort Problem

Hi All,

Just to let you know my ressults (+ one tiny question :-):
I did a bit of investigation and narrowed the "invalid" characters group to
jus one the hex 1a. My code now looks quite small:

fpath = 'c:\\pytemp\\bafir550.edi'
fl = file(fpath, 'rb')
print 'Checking file %s' % fpath
x=0
for line in fl.readlines():
x=x+1
if "" in line:
print 'Not allowed chars at line %s --- %s' % (x,line),
print "The check finished on line %s which was %s" % (x,line)

The only proble is tha in the if clause there actually is the hex 1a
character. The code works when executed from idle but when I run it from
command line, I get:

File "c:\Apps\PTOOLS\payfiles\editest.py", line 7
if "
^
SyntaxError: EOL while scanning single-quoted string

Is there any workaround?

Thanks Tom

On 20/10/05, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
>
>
> > I was going to ask why you think regex is a sledgehammer for this one,
>
> Regex's are more complex because we have to then make sure that none of
> the testchars have any special meaning as regular expression
> metacharacters. If one of those test chars, for example, contained things
> like '-' or '\\', we'd have to know to use re.escape() to be safe about
> things.
>
> Once we know regex's (and have been bitten by forgetting those issues...
> *grin*), then these factors aren't so large.
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



More information about the Tutor mailing list