Introduction to Pweave and Saving PDFs

Introducing Pweave and generating reports.

It is one thing to have a good program; it is another to be able to share it with others. MATLAB has a built-in share feature that takes the code and turns it into a shareable file format like HTML webpage, PDF, Markdown, etc. Natively, Python does not have this capability; however, you will use the third-party library, Pweave, to generate HTML from the Python program, which can be saved as a PDF for distribution. This technique allows you to open the report with a web browser and use the native “Save to PDF” functionality for distribution.

Pweave is a report generator that can run Python code, capture the input/output, and display it in several different formats. You will use the program developed to graphically show Max Q in Graphing Dynamic Pressure for a Rocket Launch and turn it into a shareable PDF. The documentation for Pweave can be found here [1], though it is spotty at best. By adding a few comment lines that simulate Markdown [2] formatting, Python programs can be turned into reports that show the input code, display the results, and hide any intermediate sections that detract from the presentation. You will make a few edits to the existing Max Q program, and then you use a command terminal to generate an HTML file that can be saved as a PDF and distributed as necessary.

Educative’s platform does not easily allow Bash scripting, so you can not directly create Pweaved reports. You can, however, show the syntax and scripting, and you can show the resulting files afterwards.

Get hands-on with 1200+ tech skills courses.