From: Russo, T. <to...@st...> - 2002-02-14 19:53:06
|
Hi all, I'm trying to augment the functionality of import so it will try to load modules out of a database if it doesn't find them on the search path. So, before anything else, I want to mimic the regular import: <file name="simple_import.py"> import imp, __builtin__ original_import = __builtin__.__import__ def import_hook(name, globals=None, locals=None, fromlist=None): return original_import(name, globals, locals, fromlist) # this is where the error occurs # Install our modified import function. __builtin__.__import__ = import_hook </file> When I run the following in cpython, everything works fine: >>> import simple_import >>> import urllib However, when I run the same commands with jython2.1 I get: <output> Traceback (innermost last): File "ex.py", line 2, in ? File "C:\cygwin\home\Administrator\Discovery\verification\python\shared\simple_im port.py", line 6, in import_hook File "C:\jython21\Lib\urllib.py", line 85, in ? File "C:\jython21\Lib\urllib.py", line 321, in URLopener File "C:\cygwin\home\Administrator\Discovery\verification\python\shared\simple_im port.py", line 6, in import_hook UnboundLocalError: local: 'globals' </output> which seems strange since globals is one of import_hook's formal parameters. I haven't been able to find this as a documented difference between cpython and jython-- is it? If not, does anyone know how I can fix this? thanks _t |