Supposing I have written a set of classes to be used in a python file and use them in a script (or python code in a different file). Now both the files require a set of modules to be imported. Should the import be included only once, or in both the files ?
File 1 : my_module.py.
import osclass myclass(object):def __init__(self,PATH):self.list_of_directories = os.listdir(PATH)
File 2 :
import os
import my_modulemy_module.m = myclass("C:\\User\\John\\Desktop")list_ = m.list_of_directoriesprint os.getcwd()
Should I be adding the line import os
to both the files ?
How does this impact the performance, supposing there are lots of modules to be imported ? Also, is a module ,once imported, reloaded in this case ?