I want to read a file, sort text inside the file and overwrite the contents of the file with sorted text.
I have been able to read and sort text, but not sure how to clear contents of the file before writing the sorted text to the file
WL01 = 'Test.txt'
with open(WL01,'r+') as WL:
lines = WL.readlines()
lines.sort()
WL.truncate()
for line in lines:
print(line, file = WL)