Initial commit (Cython implementation)
This commit is contained in:
commit
6f28ac0382
13 changed files with 1616 additions and 0 deletions
31
src-00_core/src/core.51-import.pyx
Normal file
31
src-00_core/src/core.51-import.pyx
Normal file
|
@ -0,0 +1,31 @@
|
|||
import imp
|
||||
|
||||
def import_module(path):
|
||||
"""
|
||||
Imports a python file as a module. The path can be relative or absolute.
|
||||
|
||||
Based on the work of Yuval Greenfield released into the public domain.
|
||||
"""
|
||||
|
||||
# remove the .py suffix
|
||||
mod_dn = os.path.dirname(path)
|
||||
mod_fn = os.path.basename(path)
|
||||
|
||||
if mod_fn.endswith(".py"):
|
||||
mod_name = mod_fn[:-3]
|
||||
else:
|
||||
# packages for example
|
||||
mod_name = mod_fn
|
||||
|
||||
fd = None
|
||||
|
||||
try:
|
||||
data = imp.find_module(mod_name, [mod_dn])
|
||||
module = imp.load_module(mod_name, *data)
|
||||
fd = data[0]
|
||||
|
||||
finally:
|
||||
if fd is not None:
|
||||
fd.close()
|
||||
|
||||
return module
|
Loading…
Add table
Add a link
Reference in a new issue