A custom importer package
Project description
My Import Package
This package provides custom import functionalities.
Installation
pip install my-unique-import
Usage
This package can help with custom module imports, including importing specific functions from modules, getting the location of a module, and setting up paths for module discovery.
Setting up paths
The setup_paths module allows you to add the project root directory to the Python path dynamically.
from my_import.setup_paths import setup_paths
# Call this function at the beginning of your script
setup_paths()
Custom importer
The custom_importer module provides various utilities for importing modules and functions dynamically.
Import a specific function from a module
from my_import.custom_importer import import_from
# Import the 'sqrt' function from the 'math' module
sqrt = import_from('math', 'sqrt')
print(sqrt(16)) # Output: 4.0
Import a module
from my_import.custom_importer import import_module
# Import the 'os' module
os_module = import_module('os')
print(os_module.name) # Output: posix (or 'nt' on Windows)
Get the location of a module
from my_import.custom_importer import get_location
# Get the location of the 'math' module
location = get_location('math')
print(location) # Output: The file path to the 'math' module
Functions setup_paths This function adds the project root directory to the Python path dynamically, allowing you to import modules from the project more easily.
import_from This function allows you to import a specific function from a given module.
Parameters:
module (str): The name of the module. function (str): The name of the function to import. Returns:
The imported function. import_module This function imports a module dynamically.
Parameters:
name (str): The name of the module to import. package (str, optional): The package name to use for relative imports. Returns:
The imported module. get_location This function returns the file path to the specified module.
Parameters:
module (str): The name of the module. Returns:
The file path of the module.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for my_unique_import-0.3.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 146ccc1f8c9e52600e6ee0a2f2880c178eac926c9e625edf8f51b3439ec2ad62 |
|
MD5 | dd2cb5987e18291b0c8c0f8453f20fc6 |
|
BLAKE2b-256 | 74b648429083e21263c019b86c7b0e5a5957240d88e8b108afbe9ed2cf6d7ace |