python - Sublime Editor Plugin remember variable -


i writing sublime editor 2 plugin, , remember variable duration of session. not want save variable file (it password), able run command repeatedly, , variable accessible.

i want plugin work this...

import commands, subprocess  class mycommand(sublime_plugin.textcommand):   def run(self, edit, command = "ls"):     try:       thevariable     except nameerror:       # should run first time       thevariable = "a value"     else:       # should run subsequent times       print thevariable 

one way achieve make global variable. allow access variable function. here stack question consider.

another option add instance of class. commonly done in __init__() method of class. method run class object instantiated. more information on self , __init__() consult this stack discussion. here basic example.

class mycommand(sublime_plugin.textcommand):     def __init__(self, view):         self.view = view # edit         self.thevariable = 'your value' 

this allow access variable class object after has been created. mycommandobject.thevariable. these types of variables last until window in method called closed.


Comments

Popular posts from this blog

php - Extract Text from HTTP referer -

Receive udp packets in android gstreamer -

authentication - ASP.NET Core 1.0. Bearer Token, cannot access custom claims -