Sublime Forum

Jon: Could not import exec.py and others plugin questions

#1

I want to create a new command inherited from ExecCommand, but I hit the problem that:

import exec

is not a valid Python statement, exec is a reserved keyword.
So I change to this:

execcmd = imp.load_source("execcmd", r"C:\Users\bizoo\AppData\Roaming\Sublime Text 2\Packages\Default\exec.py")

Could you please rename the exec.py in the next build ?

And is there any drawback to create a command inheriting another command ?
I didn’t find any sample in the default ST2 installation.

And in the same subject:
Could I use an init method in a command like:

class WebColorsCommand(sublime_plugin.WindowCommand): def __init__(self, *args, **kwargs): super(WebColorsCommand, self).__init__(*args, **kwargs)

0 Likes

#2

You can also import exec via:

__import__("exec")

I’ve never had a reason in inherit one command from another, but off the top of my head it should be fine.

0 Likes

#3

[quote=“jps”]You can also import exec via:

execcmd = __import__("exec")

[/quote]

Didn’t know, and way simpler than my solution.

I want to make my own build command (ExecCommand) that differ only slightly from the default one, so inheriting it seems a good idea.
I will try it and post here the problems I encounter if there are any.

Thanks for your answer.

0 Likes