I have a tab-delimeted file that contains 3 columns. I would like to add a new first column of just same number 1.
inputfile is
a 3 6
b 3 5
c 3 5
d 8 4
This is what I would like to have for my outputfile:
1 a 3 6
1 b 3 5
1 c 3 5
1 d 8 4
This is what I have so far:
#!/usr/bin/env python
import sys
import csv
f=open('inputfile.txt', 'r+')
t=[]
for line in f.readlines():
t.append('\n')
t.append(1)
f.writelines(t)
However, I am getting an error: Traceback (most recent call last): File "./py.py", line 6, in sys.stdout('inputfile.txt', 'w') TypeError: 'file' object is not callable
sys.stdoutis used for output stream. It's not a function.fout = open('outputfile.txt', 'w')andfin=open('inputfile.txt', 'r+')Also, why are you trying to read and write from your input file?sys.stdoutobject initialized to file objects corresponding to the interpreter’s standard output. It's just a regular text file like those returned by theopen()function. Read more docs.python.org/3.4/library/sys.html#sys.stdout