When I searched for this problem, I mostly saw how to import from a txt file or other file format. Not from a python file.
I need to write a function (get_seeds()) that takes in a path in string and extract a variable from that .py file. That .py file supposedly only has one variable named seeds.
Given:
path = ./data/M060812_Yac128/seeds.py
seeds = {
"HLS1": {'X': 44, 'Y': 52},
'HLS2A': {'X': 108, 'Y': 66},
'HLS2B': {'X': 91, 'Y': 85},
'FLS1': {'X': 56, 'Y': 39},
'FLS2': {'X': 104, 'Y': 61},
'BCC2': {'X': 68, 'Y': 69},
'BCC2S2': {'X': 92, 'Y': 72},
'mBC': {'X': 34, 'Y': 30}
}
get_seeds.py:
def get_seeds(path):
Path = os.path.normpaath(path)
from Path import seeds
return seeds
This obviously doesn't work... because I assume from...import... needs to be outside of the function.

from X import Ytreats X as a package or module name, and doesn't work with an existing variable. What you are trying to do is typically called dynamic import and there are several previous questions you can look up that may or may not be close enough for your purposes; I'm not confident picking the best one for you because your exact needs may differ from what I see described here.seeds.pya module andimportit like any otherimport, then access theseedsvariable in your script. See answer below