Python: How to Import a folder as a module

72 views Asked by At

I am new to Python so bear with me.

I have recently download the pdblp module in a zip form. I then made some amendments that were needed to get through specific requests. So I have this folder, is there a way where I normally write Import pdblp that I can write import 'F:\Sam\project\' as pdblp or should it not be done like this?

2

There are 2 answers

1
Razorfen On BEST ANSWER

Assuming that the module pdblp is located inside your project-directory, you can simple append your current path and then import it afterwards like so:

import sys
# Keep in mind that you need to escape backslashes by doubling them
sys.path.append("F:\\Sam\\project\\")

import pdblp
0
Basavaraju US On

You can import folder as package not module. *.py file is itself module. If you want to import folder, you need add init.py file inside the folder and then it will become package then you can import