Sublime Forum

'module' object has no attribute 'Plugin'

#1

I try to learn how to write a ST3 plugin. I tried with code from this page: sublimetext.com/docs/plugin-examples #Events.

The first error that pops up is “invalid syntax” at print command. Ok, I realized that this is python3 so I added the brackets.
Then next error emerges: No module named ‘sublimeplugin’. So I remember in some examples that people use the underscore in this name. Ok, that killed this one.
But then comes the third: ‘module’ object has no attribute ‘Plugin’ - and I don’t know what to do next.
So at the end I looked into ‘sublime_plugin’ module by dir command and, indeed there was no any Plugin class, but I saw something called “EventListener”, so I renamed it. And the result is that the code does not show any error messages but the print statements also won’t show up.

ST version - 3047

[code]import sublime, sublime_plugin

class EventDump(sublime_plugin.EventListener):
def onLoad(self, view):
print(view.fileName(), “just got loaded”)

def onPreSave(self, view):  
    print(view.fileName(), "is about to be saved")

def onPostSave(self, view):  
    print(view.fileName(), "just got saved")
      
def onNew(self, view):  
    print("new file")

def onModified(self, view):  
    print(view.fileName(), "modified")

def onActivated(self, view):  
    print(view.fileName(), "is now the active view")

def onClose(self, view):  
    print(view.fileName(), "is no more")

def onClone(self, view):  
    print(view.fileName(), "just got cloned")[/code]
0 Likes

#2

def onModified(self, view): print(view.fileName(), "modified")
Has become

def on_modified(self, view): print(view.file_name(), "modified")

The API in version 2+ of ST conforms to the PEP8 python naming conventions, for example there is now under_score instead of camelCase.
See: readthedocs.org/projects/sublim … mentation/

0 Likes