Link post
Let’s say you have a python script:
2024-01-24--evaluate-chimeras.py
2024-01-25--strand-split-artifacts.py
import ”/path/to/2024-01-25--strand-split-artifacts.py”
import
import sys import importlib sys.path.append(”/path/to/”) ssa = importlib.import_module(“2024-01-25--strand-split-artifacts”)
sys.path
Importing a Python File by Name
Link post
Let’s say you have a python script:
And you want to pull a section of it out into a separate file: You would hope you could just do something like: But this doesn’t work:import
wants a module name, not a filename. The simplest way I know to import a python file from a path is: There are a lot of complicated ways to do this, some of which avoid needing to add something tosys.path
, but for quick one-off research code better to keep it simple.