Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python code to replace first value of txt file

import os

for filename in os.listdir(os.getcwd()):
    if filename.endswith(".txt"):
            with open('{}' .format(filename), 'r+') as file:
                lines = file.readlines()
                file.seek(0, 0) #set the pointer to 0,0 cordinate of file
                for line in lines:
                    row = line.strip().split(" ")

                    if not int(row[0]):
                        row[0] = '1'
                        print(row)
                        file.write(" ".join(row) + "
")
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #code #replace #txt #file
ADD COMMENT
Topic
Name
8+1 =