gpt4 book ai didi

python - 崇高文本 3 API : Get all text from a file

转载 作者:太空狗 更新时间:2023-10-29 17:41:29 31 4
gpt4 key购买 nike


我正在尝试为 sublime text 3 创建一个插件。
现在我只能选择一个窗口中的所有文本并将其复制到另一个窗口中。
代码:

import sublime, sublime_plugin

class PrintCodeCommand(sublime_plugin.WindowCommand):
def run(self):
# for each caracter, add it to a string with the substr method
s = ""
for x in range(0,self.window.active_view().size()):
s += self.window.active_view().substr(x)
newFile = self.window.new_file()
newFile.run_command("test",{"textBuffer": s})

class Test(sublime_plugin.TextCommand):
def run(self, edit, textBuffer):
self.view.insert(edit, 0, textBuffer)

你知道更好/更简单的方法吗?
谢谢!

最佳答案

您可以通过以下方式获取当前文档的内容:

contents = self.view.substr(sublime.Region(0, self.view.size()))

关于python - 崇高文本 3 API : Get all text from a file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20182008/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com