4 ms·
Wait what? I thought Python was an interpreted language. Did I miss something?
by edem 6y ago
Wait what? I thought Python was an interpreted language. Did I miss something?
- nonameiguess 6y agoImported modules are compiled to bytecode and frozen on import, so changing the code in-place won't change what actually get run when the code is called unless you clear the bytecode cache and re-import. importlib provide a reload method for this purpose: https://docs.python.org/3.8/library/importlib.html#importlib.reload https://docs.python.org/3.8/library/importlib.html#importlib...
- dfilppi 6y agoInteresting. I've done it with no issues on both 27 and 36. Just edit the code directly in site-packages.
- coldtea 6y agoSo? Doesn't change the fact that once you've intepreted a function in some file, you've interpreted it and now it's in memory, and you're going to use the same as long as your program runs (even if you try to reload the module). (I mean, this is the default case without using something like this project, or other tricks).
- breuleux 6y agoPython doesn't re-read a function's source code from the filesystem every time it calls it, and that would be a bad idea in general since you'd inadvertently crash your running programs during development. This watches for changes on the filesystem and injects them into the running program as well as it can, basically keeping the current program state but with new behaviour. This is kind of a footgun and there are many changes you can make that will crash or ruin the process, but if you're aware of the limitations it can be pretty useful.