Sublime Text accessing view file name error
Question: I am new to Python, and Sublime Text plugin development, and I don't know what
I'm doing wrong here. I am using Sublime Text 3. I'm trying to create a plugin
that will copy the file name to the clipboard. Can anyone help me understand
this python error and/or offer a solution?

    
    
    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")
    

and the error, when I call the plugin from the console, is:

    
    
    >>> 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'
    

When I do:

    
    
    sublime.set_clipboard(view.file_name())
    

from the conosole, it works! Why?


Answer: Try `self.view.file_name()` rather than `sublime.View.file_name()`. You have a
reference to an instance of the view for your TextCommand. It was written for
ST2, but you may want to take a look at this tutorial

<http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-
text-2-plugin/>

