I have several modules, I would like to reload without having to restart Sublime Text, while I am developing a Sublime Text package.
I am running Sublime Text build 3142 which comes with python3.3
running continuously its packages/plugins. However while developing a plugin, I import a third part module I added to path as:
import os
import sys
def assert_path(module):
"""
Import a module from a relative path
https://stackoverflow.com/questions/279237/import-a-module-from-a-relative-path
"""
if module not in sys.path:
sys.path.insert( 0, module )
current_directory = os.path.dirname( os.path.realpath( __file__ ) )
assert_path( os.path.join( current_directory, 'six' ) ) # https://github.com/benjaminp/six
import six
But when I edit the source code of the module six
I need to close and open Sublime Text again, otherwise Sublime Text does not gets the changes to the six
python module.
Some code I have tried so far:
print( sys.modules )
import git_wrapper
imp.reload( find_forks )
imp.reload( git_wrapper )
imp.reload( sys )
To list all imported modules, you can use sys.modules.values()
.
import sys
sys.modules.values()
sys.modules
is a dictionary that maps the string names of modules to their references.
To reload modules, you can loop over the returned list from above and call importlib.reload
on each one:
import importlib
for module in sys.modules.values():
importlib.reload(module)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With