E
Eric Lavigne
Here is a shell command (MS-DOS):
debug\curve-fit <input.txt >output.txt
And here is a Python script that *should* do the same thing (and almost
does):
import os
inputfilename = 'input.txt'
outputfilename = 'output.txt'
inputfile = open(inputfilename,'r')
outputfile = open(outputfilename,'w')
inputstream,outputstream = os.popen2("debug\\curve-fit")
inputstream.write(inputfile.read())
inputfile.close()
inputstream.close()
outputfile.write(outputstream.read())
outputstream.close()
outputfile.close()
In the shell command, my curve-fit program processes the entire input
file. In the Python script, my curve-fit program processes all except
for the last line. Adding an extra newline to the end of my input file
fixes this problem. What did I do wrong that led to this small
difference?
On a side note, I am very new to Python so I would appreciate any
comments on style, or suggestions for simpler ways to write something
like this (seems overkill for matching one line of shell), or more
portable ways to write it (requires '\\' on windows but '/' on linux).
debug\curve-fit <input.txt >output.txt
And here is a Python script that *should* do the same thing (and almost
does):
import os
inputfilename = 'input.txt'
outputfilename = 'output.txt'
inputfile = open(inputfilename,'r')
outputfile = open(outputfilename,'w')
inputstream,outputstream = os.popen2("debug\\curve-fit")
inputstream.write(inputfile.read())
inputfile.close()
inputstream.close()
outputfile.write(outputstream.read())
outputstream.close()
outputfile.close()
In the shell command, my curve-fit program processes the entire input
file. In the Python script, my curve-fit program processes all except
for the last line. Adding an extra newline to the end of my input file
fixes this problem. What did I do wrong that led to this small
difference?
On a side note, I am very new to Python so I would appreciate any
comments on style, or suggestions for simpler ways to write something
like this (seems overkill for matching one line of shell), or more
portable ways to write it (requires '\\' on windows but '/' on linux).