'Editing a file with non .txt extension from python

I am trying to read a file with the extension .wbjn (ANSYS Workbench journal file) with basically contains python code per se, from python and change some information in it. But python does not recognize the .wbjn file, so I had to rename the .wbjn to .txt and make the changes.

But the problem with this approach is that when I trying to save the .txt extension back to .wbjn, the contents of the file is erased.

How do I do this in a better way ? Is there a library to read files with such extensions or is there another logic to solve this problem ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source