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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -