I would like to have a file "functions.py" where I collect functions that might be usefull.
Different functions may require different imports. Instead of importing them all at the beginning I would like each function to only import if it has not already been imported.
I have tried -
Obviously the scope of the "import os" is limited to the if block.
Is there a way of making the "import os" global?
Different functions may require different imports. Instead of importing them all at the beginning I would like each function to only import if it has not already been imported.
I have tried -
#!/usr/bin/env python3 """ Reuseable functions """ import sys def filesize(url): """ Reports size of file pointed to by url. """ if "os" not in sys.modules: import os return os.path.getsize(url)My IDE warns me that "os" after "return" is an unresolved reference.
Obviously the scope of the "import os" is limited to the if block.
Is there a way of making the "import os" global?