Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获取升华文本3列中每个活动选项卡的内容?_Python_Python 3.x_Sublimetext3_Sublimetext_Sublime Text Plugin - Fatal编程技术网

Python 如何获取升华文本3列中每个活动选项卡的内容?

Python 如何获取升华文本3列中每个活动选项卡的内容?,python,python-3.x,sublimetext3,sublimetext,sublime-text-plugin,Python,Python 3.x,Sublimetext3,Sublimetext,Sublime Text Plugin,我正在为Sublime编写一个插件,可以通过self.view获取活动视图的内容。但如果在不同的列中有两个打开的文件,如何通过获取每个窗口中活动选项卡的内容(或至少window.id)?是否应通过views()方法sublime.Window类来完成 class ExampleCommand(sublime_plugin.TextCommand): def run(self, edit): print (self.view.id()) ->它起作用了 class Tes

我正在为Sublime编写一个插件,可以通过
self.view
获取活动视图的内容。但如果在不同的列中有两个打开的文件,如何通过获取每个窗口中活动选项卡的内容(或至少
window.id
)?是否应通过
views()
方法
sublime.Window
类来完成

class ExampleCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        print (self.view.id())
->它起作用了

class TestCommand(sublime_plugin.WindowCommand):
    def run(self, edit):
        print (self.window.views())
->当我运行
view.run_命令('test')


非常感谢您的任何建议。

如果您查看链接的文档,
self.window.views()
将返回视图列表。视图是对象,无法打印。请尝试以下方法:

class TestCommand(sublime_plugin.WindowCommand):
    def run(self):
        print([view.id() for view in self.window.views()])
这将打印窗口中每个视图的唯一id。如果你愿意,你可以用任何方法代替

要从Sublime的控制台运行
WindowCommand
s,请使用

window.run_command("command_name")
TextCommand
是通过访问
view
对象来运行的:

view.run_command("command_name")

嗨,Matt,它不工作:(运行
>>视图时没有输出相同。运行\u命令(“测试”)
我知道了,需要运行窗口而不是查看
>>窗口。运行\u命令(“测试”)
并从运行中删除selfarguments@PaulSerikov很高兴我能帮上忙。如果这解决了你的问题,请点击左边的勾号/滴答,把它变成绿色。这标志着问题的解决,使你满意,并奖励给你和回答的人。