Posts: 4,647
Threads: 1,494
Joined: Sep 2016
i want to add a directory (folder) to the list of directories to search for modules so that it affects the script that is making the change. i prefer to add it to the front of the search list. is there a way to do this?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
so, if i want to load a specific file i could save the contents of sys.path, replace it all with the one directory that file is in, import the file, then restore the contents of sys.path?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
(Jul-04-2022, 07:07 PM)Gribouillis Wrote: This may not be the best idea because the file may contain import statements that need modules from the python path. If you remove the content of sys.path, these modules could become unreachable
i was thinking about config files i do. these are similar to INI files but use Python syntax. but your point makes sense for modules in general. i was thinking of how to detect if the config file was absent and detecting the ImportError exception. what i probably should do is have two directories with the 2nd one having the default settings (will always exist).
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
well, since it is a file intended to be in a known place, i could just do
os.stat(fn)
.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.