Skip to content

Instantly share code, notes, and snippets.

View MondeSinxi's full-sized avatar

Monde Sinxi MondeSinxi

View GitHub Profile
@MondeSinxi
MondeSinxi / dynamic_load.py
Created January 23, 2024 20:09
Dynamically load modules
import importlib.machinery
import importlib.util
import sys
def load_module(mod_name: str, filepath: str) -> None:
"""
Dynamically loads a Python module from the given file path and adds it to sys.modules.
Args:
mod_name (str): The name to be used for the loaded module.
@MondeSinxi
MondeSinxi / tail.py
Created January 23, 2024 20:01
Get the last n lines of a file.
from pathlib import Path
def tail(filename: str | Path, n: int) -> str:
"""
Get the last n lines of a file.
Parameters:
- filename (str | Path): The path to the file.
- n (int): The number of lines to retrieve from the end of the file.