Skip to content

Instantly share code, notes, and snippets.

@thoughtful-solutions
Created January 6, 2022 09:28
Show Gist options
  • Save thoughtful-solutions/bc96a1eb33bb8df7aeaffaa9454a26ab to your computer and use it in GitHub Desktop.
Save thoughtful-solutions/bc96a1eb33bb8df7aeaffaa9454a26ab to your computer and use it in GitHub Desktop.
Python Module redirection

Python Module Redirection

It is occassionally necessary to redirect where a python module is installed from.

Using a module from the existing sites structure

from pprint import pprint
from pii_generator.pii_data_generator import PIIGenerator

pii_gen = PIIGenerator(100, 'visa', True)

Using a module from the personal directory

from importlib.machinery import SourceFileLoader
pii_generator = SourceFileLoader("pii_data_generator","./pii_generator").load_module

from pii_generator.pii_data_generator import PIIGenerator

This approach means you can have both personal and sites module in place but select between them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment