[Python] Fix import in frozen app for Python 2.6 (#784)
Fix import handling for Python 2.6 to work in a frozen application. Fixes #145, reported by Thomas Kluyver.
This commit is contained in:
parent
c252d5cb40
commit
849f157efa
2 changed files with 10 additions and 5 deletions
|
|
@ -861,12 +861,13 @@ public:
|
|||
/* At here, the module may already loaded, so simply import it. */
|
||||
Printf(f_shadow, tab4 tab8 "import %s\n", module);
|
||||
Printf(f_shadow, tab4 tab8 "return %s\n", module);
|
||||
Printv(f_shadow, tab8 "if fp is not None:\n", NULL);
|
||||
Printv(f_shadow, tab4 tab8 "try:\n", NULL);
|
||||
Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
|
||||
Printv(f_shadow, tab4 tab8, "finally:\n", NULL);
|
||||
Printv(f_shadow, tab8 "try:\n", NULL);
|
||||
/* imp.load_module() handles fp being None. */
|
||||
Printf(f_shadow, tab4 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
|
||||
Printv(f_shadow, tab8, "finally:\n", NULL);
|
||||
Printv(f_shadow, tab4 tab8 "if fp is not None:\n", NULL);
|
||||
Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL);
|
||||
Printv(f_shadow, tab4 tab8, "return _mod\n", NULL);
|
||||
Printv(f_shadow, tab8, "return _mod\n", NULL);
|
||||
Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
|
||||
Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
|
||||
Printv(f_shadow, "else:\n", NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue