if type(x) is Foo:
and mysteriously failed for some data around the reload. turns out that Foo objects from before the reload were using a different class object than Foo objects after the reload (which makes sense in hindsight, as Foo was redefined). fun times debugging that! isinstance(x, Foo)(aside: i know that `isinstance` is the official way, but i just don't like the way it reads – "x is an instance of y" is an infix construct and looks weird in a prefix position. i don't really use inheritance so `type(x) is y` is good enough, and it reads very naturally)
"Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp."
Ref: http://philip.greenspun.com/research/
P.S. This is not a comment on TFA. Congratulations to the author on making Python even more interactive.
https://mail.python.org/pipermail/python-dev/2003-January/03...
It refers to this, I guess. http://www.paulgraham.com/lispfaq1.html?viewfullsite=1
"If you look at these languages in order, Java, Perl, Python, you notice an interesting pattern. At least, you notice this pattern if you are a Lisp hacker. Each one is progressively more like Lisp."
This is the basic thought. Turns out PG wrote it more explicitly than ESR.
Edit: Ah, it is https://en.wikipedia.org/wiki/Eric_S._Raymond , found after some googling
import reloading
Traceback (most recent call last):
File "<input>", line 1, in <module>
import reloading
File "/home/lucas.mccoy/.local/lib/python2.7/site-packages/reloading/__init__.py", line 1, in <module>
from .reloading import reloading
File "/home/lucas.mccoy/.local/lib/python2.7/site-packages/reloading/reloading.py", line 87
exc = exc.replace('File "<string>"', f'File "{fpath}"')
^
SyntaxError: invalid syntax diff --git a/reloading/reloading.py b/reloading/reloading.py
index 1d28e2f..1a5f981 100644
--- a/reloading/reloading.py
+++ b/reloading/reloading.py
@@ -84,9 +84,10 @@ def reloading(seq):
exec(body)
except Exception:
exc = traceback.format_exc()
- exc = exc.replace('File "<string>"', f'File "{fpath}"')
+ exc = exc.replace('File "<string>"', 'File "{}"'.format(fpath))
sys.stderr.write(exc + '\n')
- input('Edit the file and press return to continue with the next iteration')
+ print('Edit the file and press return to continue with the next iteration')
+ sys.stdin.readline()
# copy locals back into the caller's locals
for k, v in locals().items():- Always run from the back buffer
- Always scan the updated file into the front buffer
- If the front buffer is fresh AND the front buffer contains no bugs, bufferswap
[1] https://pytorch.org/tutorials/beginner/saving_loading_models...
If it doesn’t add much overhead this would be amusing for something like game dev, swapping out how the game works while running it.
Being able to loop a specific segment of code looks like a great tool for my toolbox when writing data processing code, particularly for spatial data. I will have an input dataset and be iterating on the algorithm(s) as I watch the output (often rendered in QGIS) update dynamically but requiring me to re-run the test script.
Being able to modify code during a run, where it has a heavy startup cost, is a different beast. I also wonder if Django's runserver could incorporate something like `reloading`, for even speedier reloads?
Nice that you could condense it to less than 100 lines of Python!
$ vi ~/.functions # fix
$ . ~/.functions # load latest