python - Importing the same modules in different files -


supposing have written set of classes used in python file , use them in script (or python code in different file). both files require set of modules imported. should import included once, or in both files ?

file 1 : my_module.py.

import os  class myclass(object):     def __init__(self,path):         self.list_of_directories = os.listdir(path) 

file 2 :

import os import my_module  my_module.m = myclass("c:\\user\\john\\desktop")  list_ = m.list_of_directories  print os.getcwd() 

should adding line import os both files ?

how impact performance, supposing there lots of modules imported ? also, module ,once imported, reloaded in case ?

each file using module in, must import module. each module own namespace. things explicitly import within file available in namespace. thus, if need os in both files, should import them in both files.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -