Can I insert a file in my standalone python program to be downloaded by users as a template file

Question:

I’m doing python coding self study and not a programmer.. this is my first entry here. Not sure if this is doable, (I have a very little knowledge about programming) but here it is.

Is it possible to insert a file, like a template, for the user to download in a standalone program? Tried searching online but have not been successful, maybe I just don’t know how to term it.

Any suggestion is very welcome.. thanks in advance..

When user clicks ‘Download template’, they can download an Excel template

User can download the template that I inserted in a program, that is if inserting file in a standalone program is possible.

Asked By: la_mun

||

Answers:

I think what you are asking is if you can embed a file into the .py itself (which is what I think you mean when you are saying standalone), to which the answer is no. It might be possible to compile the program into an exe using pyinstaller, but not sure how efficient or feasible that is.

If you really need this to be only one .py, I would suggest hosting it somewhere online for free and having python download the file from the url.

If I am being honest, the best way to go about doing this is to ditch the "standalone program" requirement and just shipping the template in a zip file with the .py file.

Edit: Creating the file on-demand

This slipped my mind as an idea (probably because it is the most involved and difficult way to do it), but you may be able to use something like XSLX writer to create the excel file on demand. Would require you to code a function that makes a brand new excel file from scratch, but this would not require downloads, zip files, or an executable, so it would be truly standalone (minus the added pip dependency).

Be warned though, I think python and XLSX can be finicky at times.

Answered By: sami-amer