Home Download Buy Blog Forum Support

TypeError: run() takes exactly 3 arguments (2 given)

TypeError: run() takes exactly 3 arguments (2 given)

Postby wasilto on Tue Oct 15, 2013 8:54 am

Looking at documentation

First I was getting the no module error "ImportError: No module named sublimeplugin" with
import sublime, sublimeplugin and class Rot13Command(sublimeplugin.TextCommand):
Though running view.run_command('rot13') worked(or did earlier anyway though doesn't now).

Then I added an _

Then, that got rid of the "no module..." error

but
When I enter this command in the console- view.run_command('rot13')
I get this error "TypeError: run() takes exactly 3 arguments (2 given)"


Below is my code just taken from that link but adding an underscore, how can I fix that error?

http://www.sublimetext.com/docs/plugin-examples
Code: Select all
import sublime, sublime_plugin 

class Rot13Command(sublime_plugin.TextCommand): 
    def run(self, view, args): 
        for region in view.sel(): 
            if not region.empty(): 
                # Get the selected text 
                s = view.substr(region) 
                # Transform it via rot13 
                s = s.encode('rot13') 
                # Replace the selection with transformed text 
                view.replace(region, s) 
wasilto
 
Posts: 13
Joined: Sat Sep 07, 2013 10:53 pm

Re: TypeError: run() takes exactly 3 arguments (2 given)

Postby sapphirehamster on Tue Oct 15, 2013 10:13 pm

Those examples were for Sublime 1. The API changed in 2 and 3. Depending on the version you are running, you can get the API docs here:

http://www.sublimetext.com/docs/2/api_reference.html

http://www.sublimetext.com/docs/3/api_reference.html

The new api takes an edit argument, and view is a member of the TextCommand object.
sapphirehamster
 
Posts: 88
Joined: Sun Jul 01, 2012 11:19 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 11 guests