Python Forum
importing module from specific file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
importing module from specific file
#1
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
from subdir.subdir2.subdr3 import my_deep_module
Recommended Tutorials:
Reply
#3
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
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
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).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  importing variables from module 8376459 1 247 Feb-18-2024, 02:24 PM
Last Post: deanhystad
  Extracting specific file from an archive tester_V 4 428 Jan-29-2024, 06:41 PM
Last Post: tester_V
  no module named 'docx' when importing docx MaartenRo 1 719 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Reading Specific Rows In a CSV File finndude 3 940 Dec-13-2022, 03:19 PM
Last Post: finndude
  New2Python: Help with Importing/Mapping Image Src to Image Code in File CluelessITguy 0 698 Nov-17-2022, 04:46 PM
Last Post: CluelessITguy
  My code displays too much output when importing class from a module lil_e 4 1,103 Oct-22-2022, 12:56 AM
Last Post: Larz60+
  How to extract specific data from .SRC (note pad file) Shinny_Shin 2 1,226 Jul-27-2022, 12:31 PM
Last Post: Larz60+
  Problem with importing Python file in Visual Studio Code DXav 7 4,937 Jun-15-2022, 12:54 PM
Last Post: snippsat
  importing functions from a separate python file in a separate directory Scordomaniac 3 1,331 May-17-2022, 07:49 AM
Last Post: Pedroski55
  Extracting Specific Lines from text file based on content. jokerfmj 8 2,872 Mar-28-2022, 03:38 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020