I’d like to remove the first column from a file. The file contains 3 columns separated by space and the columns has the following titles:
X’, ‘Displacement’ and ‘Force’ (Please see the image).

I have came up with the following code, but to my disappointment it doesn’t work!
f = open("datafile.txt", 'w')
for line in f:
line = line.split()
del x[0]
f.close()
Any help is much appreciated !
Esan
First of all, you’re attempting to read from a file (by iterating through the file contents) that is open for writing. This will give you an
IOError.Second, there is no variable named
xin existence (you have not declared/set one in the script). This will generate aNameError.Thirdly and finally, once you have finished (correctly) reading and editing the columns in your file, you will need to write the data back into the file.
To avoid loading a (potentially large) file into memory all at once, it is probably a good idea to read from one file (line by line) and write to a new file simultaneously.
Something like this might work: