In this code:
global ftp_client
you declare ftp_client
as a global variable. This means that it lives at the module level (where are your classes, for example).
The second line is incorrect. You want to assign a global variable, but instead you set an instance attribute with the same name.
It should be:
global ftp_client ftp_client = ftplib.FTP('foo')
But let me suggest a different approach. It is common practice to put such things inside a class, since it is shared by all instances of that class.
class FtpFileCommand(sublime_plugin.TextCommand): ftp_client = None def run(self, args): FtpFileCommand.ftp_client = ftplib.FTP('foo')
Note that the method does not use self
, so it can also be a class method:
class FtpFileCommand(sublime_plugin.TextCommand): ftp_client = None @classmethod def run(cls, args): cls.ftp_client = ftplib.FTP('foo')
This way you get the class as the first argument, and you can use it to access the FTP client without using the class name.
source share