Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.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 升华API:set#u read#u only isn';行不通_Python_Sublimetext2_Sublimetext - Fatal编程技术网

Python 升华API:set#u read#u only isn';行不通

Python 升华API:set#u read#u only isn';行不通,python,sublimetext2,sublimetext,Python,Sublimetext2,Sublimetext,我似乎无法插入通过“打开文件”创建的视图: 我的目标是创建一个插件,将所选文本提取到一个新文件中。当我将insert更改为使用new\u file而不是open\u file时,它工作得很好。你知道我遗漏了什么吗?你确定视图已经加载了吗?来自API文档 请注意,由于文件加载是异步的,因此在返回的视图的is_load()方法返回False之前,无法对其执行操作 import sublime, sublime_plugin, re, os.path class ExtractToViewComma

我似乎无法插入通过“打开文件”创建的视图:


我的目标是创建一个插件,将所选文本提取到一个新文件中。当我将insert更改为使用
new\u file
而不是
open\u file
时,它工作得很好。你知道我遗漏了什么吗?

你确定视图已经加载了吗?来自API文档

请注意,由于文件加载是异步的,因此在返回的视图的is_load()方法返回False之前,无法对其执行操作

import sublime, sublime_plugin, re, os.path

class ExtractToViewCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    view = sublime.active_window().open_file("/path/to/some/file/that/doesnt/exist/yet")
    view.set_read_only(False)
    print(view.is_read_only())         # prints True!
    e = view.begin_edit()
    view.insert(e, 0, "hello world")   # returns 0!
    view.end_edit(e)