Mar-10-2018, 11:00 AM
I have a number of files that are to be used for transcription purposes and they all need modifying. The code is nearly working, but it is duplicating the content, rather than replacing the content.
and after the script has run
I did try using the seek() command, but it produced a lot of garbage.
#!/usr/bin/python import glob, os os.chdir("/home/*******/somepath") for file in glob.glob("chunk*.txt"): print(file) f = open(file, 'r+') next = f.readline() while next != "": print(next) newline = "</s>" + next + "</s>" #f.seek(0) f.write(newline) #write updated line next = f.readline() # Close file f.close()All the files needed are called chunk*.txt, they are then opened and updated. Here is one file content befpre the code is run ..
Quote:chunk-142.txt
No the outcome will be completely different
and after the script has run
Quote:chunk-142.txt
No the outcome will be completely different</s>No the outcome will be completely different</s>
I did try using the seek() command, but it produced a lot of garbage.