Python Forum

Full Version: importing module from specific file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i wanted to import a module from a specific file that may be in a subdirectory maybe even many levels deep. the current directory will always be at some level above the module. the path will never have '/../' in it and will always be relative to the current directory. there will never be any symlinks involved. suggestions?
from subdir.subdir2.subdr3 import my_deep_module
the path is in a string, not hard coded in the source. the depth is unknown until the string with the path is known.

i found this ... what do you think?

https://stackoverflow.com/questions/6763...-full-path
my goal is to expand on the apparent limitation that mod-wsgi only operates on the file named in the apache directive. you can't just enable a directory. so my idea is that my code will take PATH_INFO and use that to select a module, and invoke that in the same way, passing on the WSGI environment (with PATH_INFO truncated as needed). that way i can make a site with a number of different scripts. my code will restrict the path as needed for security (only stuff under the script's own directory can be invoked).
it turns out you can enable a directory for mod-wsgi execution.  you just have to append the directory names with a '/' in the apache config directive.