P
Philip Carter
Hello there,
I am using:
Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32
on a win2k box.
I have the following piece of python code:
inputTmpFileOnSTAXServer='c:/temp/phil.txt'
outputTmpFileOnSTAXServer='c:/temp/philOut.txt'
import re # import regular expression module
regExp=re.compile('(\[.+\]) Tests run: (\d+), Failures: (\d+)') #
compile the regular expression
inFile=open(inputTmpFileOnSTAXServer) # open the input file for reading
outFile=open(outputTmpFileOnSTAXServer,'w') # open the output file for
writing
aLine=inFile.readline() # read a line
while aLine != "": # loop round until EOF
match=regExp.search(aLine) # search for regExp in aLine
if match: # if there is a match
aDir = match.group(1) # store the dir section of the line
attempted = match.group(2) # store the number of tests attempted
attemptedInt = int(attempted) # convert it into an int
failed = match.group(3) # store number of failures
failedInt = int(failed)
passedInt = attemptedInt - failedInt # calculate the number
passed
passedStr = str(passedInt) # convert it into a string
outLine=aDir+'\n'+attempted+' tests were
attempted\n'+passedStr+' test(s) passed\n' # create summary line in
correct format
outFile.write(outLine) # write out the summary line
aLine=inFile.readline() # read a line
outFile.close() # close the output file
inFile.close()
When I save in a file - terry.py and run it:
python terry.py
it works fine.
However, if I try and paste it into an interactive python window, I get
the following error:
.... outFile.close() # close the output file
File "<stdin>", line 14
outFile.close() # close the output file
^
SyntaxError: invalid syntax
Any idea why this is?
Thanks,
Phil
I am using:
Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32
on a win2k box.
I have the following piece of python code:
inputTmpFileOnSTAXServer='c:/temp/phil.txt'
outputTmpFileOnSTAXServer='c:/temp/philOut.txt'
import re # import regular expression module
regExp=re.compile('(\[.+\]) Tests run: (\d+), Failures: (\d+)') #
compile the regular expression
inFile=open(inputTmpFileOnSTAXServer) # open the input file for reading
outFile=open(outputTmpFileOnSTAXServer,'w') # open the output file for
writing
aLine=inFile.readline() # read a line
while aLine != "": # loop round until EOF
match=regExp.search(aLine) # search for regExp in aLine
if match: # if there is a match
aDir = match.group(1) # store the dir section of the line
attempted = match.group(2) # store the number of tests attempted
attemptedInt = int(attempted) # convert it into an int
failed = match.group(3) # store number of failures
failedInt = int(failed)
passedInt = attemptedInt - failedInt # calculate the number
passed
passedStr = str(passedInt) # convert it into a string
outLine=aDir+'\n'+attempted+' tests were
attempted\n'+passedStr+' test(s) passed\n' # create summary line in
correct format
outFile.write(outLine) # write out the summary line
aLine=inFile.readline() # read a line
outFile.close() # close the output file
inFile.close()
When I save in a file - terry.py and run it:
python terry.py
it works fine.
However, if I try and paste it into an interactive python window, I get
the following error:
.... outFile.close() # close the output file
File "<stdin>", line 14
outFile.close() # close the output file
^
SyntaxError: invalid syntax
Any idea why this is?
Thanks,
Phil