pythonmodulepdblp

Python: How to Import a folder as a module


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?


Solution

  • 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