Reloading imported modules
See original GitHub issueI have a feature request, or at least a discussion on one.
Use case
NB. This is very simplified, I have one project with 8 different local module imports, and I intend to use more in the next.
driving_dims.py:
box = (100, 20, 30)
main.py:
import cadquery as cq
import driving_dims
a = cq.Workplane("front").box(*driving_dims.box)
show_object(a)
- start cq-editor, load
main.py
, render - change
box
indriving_dims.py
edit: just realised it’s relevant that I use vim and edit all my files externally from cq-editor - render again, new dimensions are not loaded
User side solution
I naively restarted cq-editor a lot until I discovered I could change my import from
import driving_dims
to
import importlib
import driving_dims
importlib.reload(driving_dims)
to have the module reloaded every time the script is executed.
I kind of like this solution because you can be explicit about what needs to be reloaded every time.
Feature suggestion
I would be happy with just documenting the importlib.reload
method, but the devs seem to be going for a quite user-friendly feel, so perhaps they want to implement automatic reloading of any module in the working script directory?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Reloading modules in Python - GeeksforGeeks
The reload() is a previously imported module. If you've altered the module source file using an outside editor and want to test the...
Read more >Reloading a Module - Real Python
In this video, I'll show you about reloading a module. Up to now, you've been simply importing a module once. Even if you...
Read more >Reloading modules in Python? - Tutorialspoint
The reload() is used to reload a previously imported module or loaded module. This comes handy in a situation where you repeatedly run...
Read more >How do I unload (reload) a Python module? - Stack Overflow
You can reload a module when it has already been imported by using importlib.reload() : from importlib import reload # Python 3.4+ import...
Read more >Reloading All Loaded Modules - Python Cookbook [Book]
You can use the reload function, but this is difficult if you perform changes in a module that isn't directly imported by your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This was implemented in #272.
main.py
, renderbox
indriving_dims.py
With Preferences “Autoreload: watch imported modules” selected:
main.py
, renderdriving_dims.py
, render updates automaticallyIt should be possible, e.g. like so: