I have a Flask backend in which I import the magic
module on module level, but I use it only in one function:
import magic
def wizard(filename):
return magic.from_file(filename)
As magic has a dependency to a C library which I can't install on windows and as this function is the only place where magic
is used, I wondered if there is a drawback (or even an advantage) of moving the import to the function:
def wizard(filename):
import magic
return magic.from_file(filename)
Would the overhead of importing magic
only matter for the first user who uses the function and later it's there for everybody? Or does Flask / Python load it again and again?