python - Is this correct to import module only in function, not in a start of file? -
so, have itchy question import modulename , should put operator. in start of file or in function?
import some_module def main(): some_module.somestuff() or:
def main(): import some_module some_module.somestuff() but if i'll use in more 1 function? correct or stupid? or need create class __init__ function this: self.module = some_module.somestuff()? , call in other functions under class?
creating class import not pythonic it's bad. should import module name space calling functions in module or can import specific functions:
from some_module import somefunc1, somefunc2 # or import some_module some_module.somefunc1() import statement must @ top of source file(look pep8)
Comments
Post a Comment