栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在崇高的条件下,为什么def run在一种情况下可以工作而在另一种情况下不能工作?我如何使它运行?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在崇高的条件下,为什么def run在一种情况下可以工作而在另一种情况下不能工作?我如何使它运行?

对于#1,您是对的。在Python中,这意味着继承。派生类定义的语法如下所示

class DerivedClass(baseClassName):

Python中的继承

对于#2,Sublime Text
2支持三种类型的命令。

run
运行命令时将调用该方法。除了必需的参数之外,您还可以根据需要定义任意数量的参数
run
。当您运行带有附加参数的命令时,需要在映射中传递这些参数。

  • ApplicationCommand
    :整个Sublime Text 2的命令。不需要参数。
  • WindowCommand
    :命令窗口。没有必需的参数。
  • TextCommand
    :用于查看的命令。一个必需的参数
    edit

对于#3,如何运行:

  • ApplicationCommand
    sublime.run_command('application_command_name')
    。API参考中
    run_command
    有关sublime模块的检查功能。
  • WindowCommand
    window.run_command('window_command_name')
    。的检查
    run_command
    方法
    sublime.Window
  • TextCommand
    view.run_command('text_command_name')
    。检查
    run_command
    方法
    sublime.View

示例1:不带额外参数的命令

import sublime, sublime_pluginclass TestApplicationCommand(sublime_plugin.ApplicationCommand):    def run(self):        print("running TestApplicationCommand")import sublime, sublime_pluginclass TestWindowCommand(sublime_plugin.WindowCommand):    def run(self):        print("running TestWindowCommand")import sublime, sublime_pluginclass TestTextCommand(sublime_plugin.TextCommand):    def run(self, edit):        print("running TestTextCommand")

运行以下命令:

>>> sublime.run_command('test_application')running TestApplicationCommand>>> window.run_command('test_window')running TestWindowCommand>>> view.run_command('test_text')running TestTextCommand

示例2:带有附加参数的命令

import sublime, sublime_pluginclass TestApplicationCommand(sublime_plugin.ApplicationCommand):    def run(self, arg1, arg2):        print("running TestApplicationCommand")        print("arg1: " + arg1)        print("arg2: " + arg2)import sublime, sublime_pluginclass TestWindowCommand(sublime_plugin.WindowCommand):    def run(self, arg1, arg2):        print("running TestWindowCommand")        print("arg1: " + arg1)        print("arg2: " + arg2)import sublime, sublime_pluginclass TestTextCommand(sublime_plugin.TextCommand):    def run(self, edit, arg1, arg2):        print("running TestTextCommand")        print("arg1: " + arg1)        print("arg2: " + arg2)

运行以下命令:

>>> sublime.run_command('test_application', {'arg1' : '1', 'arg2' : '2'})running TestApplicationCommandarg1: 1arg2: 2>>> window.run_command('test_window', {'arg1' : '1', 'arg2' : '2'})running TestWindowCommandarg1: 1arg2: 2>>> view.run_command('test_text', {'arg1' : '1', 'arg2' : '2'})running TestTextCommandarg1: 1arg2: 2


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/517037.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号