Simpler Python module loading
Simplification possible given Python 2.7 is now the minimum supported. Issue #848
This commit is contained in:
parent
03323f5c8b
commit
2a00d0f784
2 changed files with 15 additions and 22 deletions
|
|
@ -6282,13 +6282,10 @@ The code is generated into the pure Python module, foo.py, and merely imports th
|
|||
|
||||
<div class="targetlang">
|
||||
<pre>
|
||||
def swig_import_helper():
|
||||
import importlib
|
||||
pkg = __package__ if __package__ else __name__.rpartition('.')[0]
|
||||
mname = '.'.join((pkg, '_foo')).lstrip('.')
|
||||
return importlib.import_module(mname)
|
||||
_foo = swig_import_helper()
|
||||
del swig_import_helper
|
||||
if __package__ or __name__.rpartition('.')[0]:
|
||||
from . import _foo
|
||||
else:
|
||||
import _foo
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue