|
From: Ted B. <te...@et...> - 2001-09-04 10:39:12
|
Background: I'm distributing a java application in executable jar format. My goal is to offer python as a scripting engine for the application, and to that end I wish to distribute the jython Lib/ modules as part of the jar, such that user scripts can import these modules. 1. Modules in the root directory of the jar may be imported normally 2. Modules in a subdirectory of the jar may be imported iff a __init__.py module also appears in that subdirectory. 3. Attempts to import modules from a subdirectory without a corresponding __init__.py file yield a "ImportError: no module named X" exception, where X is the subdirectory. I assume this is because /path/to/jarfile is a valid addition to the sys.path and /path/to/jarfile!/subdirectory is not a valid addition and is ignored. Am I correct in also assuming that the __init__.py file causes the python interpreter to treat the *directory* as a module itself? If this is the case, why does an __init__.py placed in the jar root directory not get executed, allowing me to import subdirectories without the need for __init__.py files in them? Honestly, this isn't a really big deal. It makes for some strange looking import clauses if you're used to CPython ( from Lib import string ), but it does the job. My biggest concern was a desire to modify the Lib/ tree as little as possible, not at all being my preference. I know little enough about hard-core python hacking that I didn't want to mess with anything. Ted |