Import full module or just what i need in order to reduce memory

python

Solution

Importing the module doesn't waste anything; the module is always fully imported (into the `sys.modules` mapping), so whether you use `import ftplib` or `from ftplib import FTP` makes no odds.

I elaborate on why this is and what importing a module really means over on Programmers, on a cross-site duplicate question at 'import module' vs. 'from module import function'.

Problem

I was thinking if is relevant to import just what i need from a module in order to reduce the memory consume of any script, or should i just import everything ? I believe if i start to write that way could consume more time write , but it worth it? I mean, could reduce the chance of more usage of the memory? With the code bellow, a tleast just the relevant parts is an current example of what im planning to do: ``` from ftplib import FTP as FTP_LIB from ftplib.FTP import connect as FTP_CONNECT from ftplib.FTP import login AS FTP_LOGIN from ftplib.FTP import cwd as FTP_CWD from ftplib.FTP import storbinary as FTP_STORE_BIN from ftplib.FTP import retrbinary as FTP_RETRIV_BIN from ftplib.FTP import delete as FTP_DELETE from ftplib.FTP import quit as FTP_QUIT from zipfile import ZipFile from zipfile import ZIP_DEFLATED from sys import exit as SYS_EXIT #-------------------------------------------------------------------------- # FTP Download #-------------------------------------------------------------------------- def get_file(self, iServer, ftpPort, login, pwd, fileName, path): parts = iServer.split(":") host = parts[0] ftp = FTP_LIB() try: FTP_CONNECT(host, ftpPort, 20) FTP_LOGIN(login, pwd) FTP_CWD(path) FTP_RETRIV_BIN('RETR ' + fileName, open(fileName, 'wb').write) except Exception, e: print " Download failed : " + str(e) SYS_EXIT(1) finally: FTP_QUIT() ``` Thanks in advance.

Original source