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.