diff --git a/swig/Source/Modules/python.cxx b/swig/Source/Modules/python.cxx index a6801fc..7aa08ba 100644 --- a/swig/Source/Modules/python.cxx +++ b/swig/Source/Modules/python.cxx @@ -846,7 +846,8 @@ public: Printv(default_import_code, "if _swig_python_version_info >= (2, 7, 0):\n", NULL); Printv(default_import_code, tab4, "def swig_import_helper():\n", NULL); Printv(default_import_code, tab8, "import importlib\n", NULL); - Printv(default_import_code, tab8, "pkg = __name__.rpartition('.')[0]\n", NULL); + Printv(default_import_code, tab8, "pkg_parts = __name__.rpartition('.')\n", NULL); + Printv(default_import_code, tab8, "pkg = pkg_parts[0] if pkg_parts[1] == '.' else pkg_parts[2]\n", NULL); Printf(default_import_code, tab8 "mname = '.'.join((pkg, '%s')).lstrip('.')\n", module); Printv(default_import_code, tab8, "try:\n", NULL); Printv(default_import_code, tab8, tab4, "return importlib.import_module(mname)\n", NULL);