Python's driving me mad. Invalid token?

Sean 'Shaleh' Perry shalehperry at attbi.com
Fri Oct 18 03:03:10 EDT 2002


On Thursday 17 October 2002 23:45, Erik Max Francis wrote:
> Jim wrote:
> >   File "C:\***\backup.py",
> > line 42
> >     MainProg()
> >              ^
> > SyntaxError: invalid token
> >
> > Any idea at all on what this means?
>
> It's an indentation problem; you're using inconsistent indentation
> and/or mixed use of tabs and spaces which are confusing the interpreter.

no, it isn't, it is far more insidious.

def CopyFiles(dirname,fnamelist):
    for name in fnamelist:
        destFile = open((dirname+"""\"""+name),'w')
        srcFile = open(name,"r")
        destFile.write(srcFile.read())
        srcFile.close()
        destFile.close()

note the backslash in the open() call.  This yields """, an escaped ", "" so 
python keeps looking for the end of the triple quoted string.

import os.path
os.path.join(dirname, name)

solves it.




More information about the Python-list mailing list