For this task you may want to not work with files in your program directly, but work with standard input (input()
or raw_input()
in Python 2) and standard output (just print()
).
Then you specify input and output file names during invocation of your script:
python script.py < file.txt > answer.txt
With this scheme you can have a program like this (Python 2.7):
while (True):
try:
x, y, z = [int(val) for val in raw_input().split(',')]
print (x + y + z)
except EOFError:
pass