Python's driving me mad. Invalid token?

Paul.Casteels at ua.ac.be Paul.Casteels at ua.ac.be
Fri Oct 18 03:05:10 EDT 2002


It's the line 
  destFile = open((dirname+"""\"""+name),'w')

\" seems to be treate as one character, r'\' also does not work. 
You will have to use r'\\'. This is strange, because r'\a' does work as
expected.

	Paul Casteels


Jim <javagrunge at hotmail.com> wrote:
: Today I installed Python 2.2.2. I wrote a short script that backs up
: project files, and I'm getting a weird error that I've never gotten
: before. I have spent hours trying to figure this out - can anyone
: help?

: My code:

: import time
: import os

: class Elements:
:        def __init__(self):
:                self.Group = ""
:                self.FileList = []

: def ParseFile(fname):
:        f = file(fname,"r")
:        fl = f.readlines()
:        for stringy in fl:
:                if stringy[-1] == "\n": stringy = stringy[:-1]
:        el = Elements()
:        el.Group = fl[0]
:        el.FileList = fl[1:]
:        f.close()
:        return el

: def createBackupDir(baseName):
:        timeFormatString = """%m-%d-%Y %H.%M"""
:        timeStr = time.strftime(timeFormatString)
:        if baseName[-1] == "\n": baseName = baseName[:-1]
:        dirName = baseName + " " + timeStr
:        os.mkdir(dirName)
:        return dirName

: 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()

: def MainProg():
:        parsed = ParseFile("test.bs")
:        D = createBackupDir(parsed.Group)
:        CopyFiles(D,parsed.FileList)

: MainProg()


: The error:

:  File "C:\***\backup.py",
: line 42
:    MainProg()
:             ^
: SyntaxError: invalid token

: Any idea at all on what this means?

: Jim

-- 
Paul Casteels		Paul.Casteels at ua.ac.be	Tel: +32.3.8202455
						Fax: +32.3.8202470
University of Antwerp	Dpt.Physics
Universiteitsplein 1
B-2610 Wilrijk
Belgium



More information about the Python-list mailing list