Skip to main content

Make .docx files executable for the python interpreter

Project description

Pydocxrunner

PyPI version Build Status GitHub license

Is Word or Libre Office Writer you favorite IDE? Do you recognize docx as a superior file format? And are you tired of the high effort required to execute the code stored in .docxfiles? Then don't worry, pydocxrunneris the tool of your dreams. pydocxrunner provides a simple command to make a .docx file executable like any normal .py file.

Features

  • Make .docxfiles executable via the python command. Once the file is made executable, pydocxrunner is no longer required.
  • The .docx file can then be executed on any device with python installed.
  • What else do you need?

Example

Assuming you have a file called printquad.docx with the following content:

for i in range(10):
    print(i)

Then you can make it executable using pydocxrunner:

$ pydocxrunner printquad.docx

And execute it (on any device having python3 installed):

$ python3 printquad.docx
0
1
4
9
16
25
36
49
64
81

How it works

Unknown to most, .docx files are .zip files with a fancy name. Also unknown to most, python can execute .zip files. pydocxrunner writes a simple __main__.py file as well as python-docx2txt into the .docx file. The __main__.py script will be executed by the python interpreter and read the contents of the .docx file. This content is then passed to an exec() call.

Caveats

  • This is not tested beyond a few simple statements
  • I do not recommend using this tool for production
  • An internet connection is required when running pydocxrunner as python-docx2txt needs to be downloaded. No connection is required to actually execute the .docx file.
  • You still have to use ' and " for strings, and will not work.

TODO

  • Make this work with other types of documents
  • Make this work with other languages
  • Find a better solution for installing python-docx2txt

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydocxrunner-0.0.3.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

pydocxrunner-0.0.3-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page