I have a series of values in one file and I want to add two "descriptors" to all the series of values using python script.
Example:
Values:
1 2 3
1 3 4
Descriptors:
Ford truck
End result:
1 2 3 Ford truck
1 3 4 Ford truck
I would appreciate any help. I have looked at hstack, but am unsure this is the best approach.
Assuming that the name of the raw file is fname
and the name of the output file should be outputFile
you could do this:
with open(fname) as inputFile:
content = inputFile.readlines()
content = [x.strip() + "Ford truck" for x in content]
with open(ofname, "w") as outputFile:
for item in content:
outputFile.write("%s\n" % item)
This code will read all lines of your raw input file, removes all trailing white space, adds Ford truck
to each line and saves the result on the output file.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments