I have a regular text.txt file that is being used in a different program with the file extension .mo
I want to access the text with open(), but for that, I have to change the extension of the file. In the end, the extension should reverse to .mo :
path = "dymtest.txt"
file_name = Path(path_dym)
file_name.rename(file_name.with_suffix(".txt"))
with open(file_name) as chat:
lines = chat.readlines()
file_name.rename(file_name.with_suffix(".txt"))
I'd say that opening the file as a .mo to read the text should be possible. Additionally, a solution needs to be able to read and write that file.
As mentioned above, python don't care about file name (including extension). While you do know what is the file structure and how to work with it — just do it.
If .mo
actually contains text — open this file in text mode (which is default), read/process/write it.