Sublime Forum

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

#1

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?

sublimetext.com/docs/plugin-examples

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)  
0 Likes

#2

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:

sublimetext.com/docs/2/api_reference.html

sublimetext.com/docs/3/api_reference.html

The new api takes an edit argument, and view is a member of the TextCommand object.

0 Likes