0

Is there a way to add a directory to the locations that python look at when you call __import__ ?

I need to import some scripts from a user folder at runtime, and since __import__ doesn't accept absolute file names, I'd like to try this. Copying the script to the program directory isn't a solution I'm willing to risk (requires administrator privileges on some machines).

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by scru
1

You simply append the directory to PYTHONPATH before you import your custom module:

import sys
# appends to PYTHONPATH  the location of the example codes
sys.path.append(r'C:\Python25\Examples')
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.