old_file= open ("file_Path","r")
new_file = open ("file_Path","w")
for line in old_file:
if "
new_file.write(line.replace("oldtext","newtext"))
else:
new_file.write(line)
In the above example we are opening a file in read and write mode and performing some basic operations.
Based on a condition we are trying to replace some content in the file and writing the new thing in a different file.
this code works as is , you just have to give the appropriate values. sys is the only module you will be needing.
No comments:
Post a Comment