Skip to content

Instantly share code, notes, and snippets.

@zzzeek
Last active August 29, 2015 13:59
Show Gist options
  • Save zzzeek/10732923 to your computer and use it in GitHub Desktop.
Save zzzeek/10732923 to your computer and use it in GitHub Desktop.
the ever continuing struggle to load a .py file as a module without deprecation warnings
import sys
def load_py_file(path):
if sys.version_info >= (3, 4):
"""???? what goes here ????
load_module() is deprecated? Docs at
https://docs.python.org/3.4/library/importlib.html#importlib.abc.Loader.load_module
https://docs.python.org/3.4/library/importlib.html#importlib.abc.Loader.exec_module
completely unclear, what does "exec_module()" do? is that the replacement?
can we please stop changing the API here?"""
elif sys.version_info >= (3,3):
from importlib import machinery
return machinery.SourceFileLoader("plugin_base", path).load_module()
else:
# "imp" is deprecated in 3.3
import imp
return imp.load_source("plugin_base", path)
load_py_file("test2.py")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment