Text files from Thonny

I apologise in advance if this a “Noddy” question but if you don’t know, you don’t know! How do I create a programme listing, complete with line numbers, from Thonny as a simple text file that can be read by anyone without Python or Thonny. Thonny will only let me save with a “.py” suffix.

You should be able to change the file extension from .py to .txt. You won’t get the line numbers but the rest of it should be there as a text file.

One way to do it is to open the py file with notepad, then do a save as txt file.

EDIT: The indents are very important, as far as Python is concerned. If you lose the indents in the process of saving the file as a text file, it won’t ever work in python again without restoring them.

From within Thonny I managed to get exactly the result I wanted as a .html file but I can’t repeat it!

It looks like a simple “print” from the “File” tab in Thonny with the required file open does exactly what I needed. It produces an “html” file complete with line numbers. I think I was over-complicating the whole issue.

2 Likes