Skip to content

Import module from path #15

Open
Open
@chendaniely

Description

@chendaniely

From here: https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path

we can actually import module files from a full python path. Since here() will return a full path, we can write a function that makes it easier to import.

I don't want to name the function import, but something like:

import pyprojroot

# will append `src` to the import path (temporarily)
pyprojroot. proj_import(here("./src"))` 
import my_module1
import my_module2

# will import module directly, given a .py script
pyprojroot. proj_import(here("./src/my_module.py"))` 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions