Skip to content

Instantly share code, notes, and snippets.

View cmower's full-sized avatar

Chris Mower cmower

View GitHub Profile
@cmower
cmower / import_from_file.py
Created July 13, 2024 14:52
Given a function name (string), and a path to a Python script (string), import the function from the script.
import os
import sys
import importlib.util
from typing import Callable
def import_from_file(script_path: str, function_name: str) -> Callable:
"""
Imports a function from a Python script file given the file path and the function name.
Args: