Jan-20-2018, 03:20 PM
(This post was last modified: Jan-20-2018, 03:22 PM by Gribouillis.)
The following script (download it here) named
The script is based on the AWESOME module
I typically use it while developing myprog.py or one of the watched files, in order to have immediate feedback from python every time I type Ctrl-s in my editor to save the file I'm working on.
autopython3
runs a python script every time it is changed on disk. It also supports watching other files and running the script when one of these files is changed.The script is based on the AWESOME module
doit
(according to doit's documentation, this script should work only in LINUX and MAC OSX). Ubuntu users can install it withsudo apt install python3-doitIn order to run the below script, use a command line such as
autopython3 myprog.py autopython3 -w foo.txt bar.png baz.pdf -- myprog.pyThen the script
myprog.py
is executed every time one of the files mentioned on the command line is changed on disk. 
#!/usr/bin/env python3 # -*-coding: utf8-*- '''doc ''' __version__ = '0.1.0' from argparse import ArgumentParser import sys def task_AutoExecution(): """my doc""" yield { 'basename': 'AutoExecution', 'actions': ['PYTHONIOENCODING="utf8" {python} {script}'.format(python=sys.executable, script=SCRIPT)], 'watch': [PROG] + WATCH, 'verbosity': 2, } if __name__ == '__main__': parser = ArgumentParser(description='Automatically runs a python script every time it is changed on disk') parser.add_argument('script', metavar='SCRIPT', help='python script to execute', action='store') parser.add_argument('-w', '--watch', metavar='FILE', help='additional file to watch (end arglist with --)', nargs='*') args = parser.parse_args() SCRIPT = args.script PROG = SCRIPT.strip().split()[0] WATCH = args.watch or [] sys.argv[1:] = ['auto',] import doit doit.run(globals())