I have a folder with multiple ascii coded txt files and would like to open all of them, read all the lines, write into the file and remove whitespaces if any and change/delete the first number of the 4th object in the list at the same time.
One file content looks like that, as a list:
[' 0.200000\n', ' 0.000000\n', ' 0.000000\n', ' -0.200000\n', ' 3400000.100000\n', ' 5867999.900000\n']
At the end it should look like that:
['0.200000\n', '0.000000\n', '0.000000\n', '-0.200000\n', '400000.100000\n', '5867999.900000\n']
Whithout whitespaces and the first number in the 4th object
My code so far:
import glob, fileinput, os, shutil, string, tempfile, linecache,sys
pfad = "D:\\Test\\"
filelist = glob.glob(pfad+"*.tfw")
if not filelist:
print "none tfw-file found"
sys.exit("nothing to convert")
for fileName in fileinput.input(filelist,inplace=True):
data_list = [''.join(s.split()) for s in data_list]
data_list[4]= data_list[4][1:]
print(data_list)
sys.stdout.write(data_list)
i have managed to modify the files at the same time but still can't overwrite them with a new content. I recieve the following error: "data_list = [''.join(s.split()) for s in data_list] NameError: name 'data_list' is not defined"