Python Forum
How to import another Python in different directory? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to import another Python in different directory? (/thread-38322.html)



How to import another Python in different directory? - dee - Sep-28-2022

Hello,
I would like to get help on importing another Python program in different directory. I didn't seem finding that is straight forward from googling.
Thanks.


RE: How to import another Python in different directory? - dee - Sep-28-2022

I figured it out. Thanks.

Sorry. I don't know how to delete the post.


RE: How to import another Python in different directory? - deanhystad - Sep-28-2022

Instead of deleting the post, post your answer to the question. There might be a better way to solve this problem, or somebody else might have the same problem and would benefit from reading your solution.


RE: How to import another Python in different directory? - dee - Sep-28-2022

Added the directory where the Python program is located to the sys.path, then import the Python program.

import sys
file_dir = "c:\\Users\\dee\\Documents\\_Python"
sys.path.append( file_dir )
import Connection as conn