我是 Python 和 Sublime Text 插件开发的新手,我不知道我在这里做错了什么。我正在使用 Sublime Text 3。我正在尝试创建一个将文件名复制到剪贴板的插件。谁能帮我理解这个 python 错误和/或提供解决方案?
import sublime, sublime_plugin
class Filename_to_clipboardCommand(sublime_plugin.TextCommand):
def run(self, edit):
sublime.set_clipboard(sublime.View.file_name())
sublime.message_dialog("The full file path was copied to the clipboard")
当我从控制台调用插件时,错误是:
>>> view.run_command('filename_to_clipboard')
Traceback (most recent call last):
File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 549, in run_
return self.run(edit)
File "/Users/ivan/Library/Application Support/Sublime Text 3/Packages/Filename_to_clipboard/filename_to_clipboard.py", line 5, in run
sublime.set_clipboard(sublime.View.file_name())
TypeError: file_name() missing 1 required positional argument: 'self'
当我做:
sublime.set_clipboard(view.file_name())
从控制台,它的工作原理!为什么?