I am trying to create a function for a task I mentioned earlier for adding a new field to some files that are stored in one folder. I read about the function method in Python and followed but it does not work. I would be happy if someone could guide me about it.
def newfield(infile,outfile):
infile.readlines()
outfile = ["%s\t%s" %(item.strip(),2) for item in infile]
outfile.write("\n".join(output))
outfile.close()
return outfile
and then I try to call it:
a = open("E:/SAGA/data/2006last/test/325145404.all","r")
b = open("E:/SAGA/data/2006last/test/325145404_edit.all","w")
newfield(a,b)
Moreover, when we create a function, should we call it in a same python shell or we can same it as a file and then call it?