let\'s say we have two functions:
def ftpConnect():
ftp = FTP(\'server\')
ftp.login()
ftp.cwd(\'/path\')
def getFileList():
ftpConnect()
fi
Return ftp
from ftpConnect()
and assign the return value to a variable named ftp
:
def ftpConnect():
ftp = FTP('server')
ftp.login()
ftp.cwd('/path')
return ftp #return ftp from here
def getFileList():
ftp = ftpConnect() # assign the returned value from the
# function call to a variable
files = ftp.nlst()
print(ftp.nlst())