我有一个类blahtestCommand(sublime_plugin.ApplicationCommand)
运行,它失败了。在
另一个类,我有sublime_plugin.TextCommmand)
作品。在
我对run定义应该是什么样子有点困惑。我知道java(10年前做过一些OOP编程,我记得很清楚),但我对python知之甚少。(所以我不太了解一个类接受参数,因为它不在java中,但我会猜测它有点像“extends”-继承-或“implements”)。在
我还试图确定ST2 API documentation中的内容将告诉某人,当一个类具有参数sublime_plugin.TextCommand
时,def run行应该是这样的def run(self, edit)
,而当一个类有参数sublime_plugin.ApplicationCommand
时,def运行应该是这样的-我不知道是什么。(所以这是一个更大的谜团)
注意这里的view.run_('......')
不适用于blahtest
类,它没有打印'aaaaaaaa'
我在控制台中没有任何错误。插件-随便吧。py装好了。因此,一个类运行方法运行,而另一个类的运行方法不运行。我可以在def run和类blahtestCommand之间加一行来打印“123456789”,保存后它就会打印出来随便吧。py因为它重新加载,没有错误。只是我没有调用它的run方法view.run_命令('blahtest')
import sublime, sublime_plugin
class blahtestCommand(sublime_plugin.ApplicationCommand):
def run(self):
print "aaaaaaaaaaa"
class butthiswillworkCommand(sublime_plugin.TextCommand):
def run(self, edit):
print "bbbb"
>>> view.run_command('blahtest') >>> view.run_command('butthiswillwork') bbbb
添加 我运气很好,设法让它为WindowCommand工作
^{pr2}$关于在sublimeapi类中运行“run”,我可能会在将来进一步更新这个问题。在
对于1,你是对的。在Python中,这意味着继承。派生类定义的语法类似于
class DerivedClass(BaseClassName):
。在{a1}
对于#2,Sublime Text 2支持三种类型的命令。当您运行命令时,
run
方法被调用。除了必需的参数之外,您还可以为run
定义任意多个参数。当运行带有额外参数的命令时,需要在映射中传递这些参数。在edit
。在对于#3,如何运行:
ApplicationCommand
:sublime.run_command('application_command_name')
。检查API reference中的sublime模块的run_command
函数。在WindowCommand
:window.run_command('window_command_name')
。检查^{run_command
方法。在TextCommand
:view.run_command('text_command_name')
。检查run_command
方法^{示例1:不带额外参数的命令
运行以下命令:
^{pr2}$示例2:具有额外参数的命令
运行以下命令:
相关问题 更多 >
编程相关推荐