我为sublime text 3
创建了一个简单的插件(使用另一个我的简单模块module1
):
import sublime, sublime_plugin
import sys
sys.path.insert(0, '/Users/maks/Library/Application Support/Sublime Text 3/Packages/forStack')
import module1
class simple_pluginCommand(sublime_plugin.TextCommand):
def run(self, edit):
print("Hello World")
module1.method1()
我在sublime command line
(ctrl +`)
view.run_command('simple_plugin')
输出:
Hello World
Hello module1.method1()
module1
是......
def method1():
print("Hello module1.method1()")
然后我重构module1
(更改方法名称及其内容):
def method2():
print("Hello module1.method2()")
...使用输出保存module1:
Writing file /Users/maks/Library/Application Support/Sublime Text 3/Packages/forStack/module1.py with encoding UTF-8 (atomic)
reloading plugin forStack.module1
然后我相应地更改插件文本以调用module1.method2():
import sublime, sublime_plugin
import sys
sys.path.insert(0, '/Users/maks/Library/Application Support/Sublime Text 3/Packages/forStack')
import module1
class simple_pluginCommand(sublime_plugin.TextCommand):
def run(self, edit):
print("Hello World2")
module1.method2() #------------------------- change only here
使用输出保存:
Writing file /Users/maks/Library/Application Support/Sublime Text 3/Packages/forStack/simple_plugin.py with encoding UTF-8 (atomic)
reloading plugin forStack.simple_plugin
然后尝试再次调用simple_plugin
并输出错误:
Hello World2
Traceback (most recent call last):
File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 549, in run_
return self.run(edit)
File "/Users/maks/Library/Application Support/Sublime Text 3/Packages/forStack/simple_plugin.py", line 10, in run
module1.method2()
AttributeError: 'module' object has no attribute 'method2'
似乎它“缓存”某个地方module1
并且不接受更改。那么如何禁用或刷新“缓存”?
更新
现在我可以通过两种方式刷新“缓存”:
module1
重命名为module2
。 这两种方法都太浪费时间了。