I have file with only bare data like: foo.py
TL = {
'aa': {'L1104205608': {'ada': {'bb': 'APC', 'ip_addr': '10.44.184.12', 'port': 2}},
'L1104205616': {'ada': {'bb': 'APC', 'ip_addr': '10.44.184.13', 'port': 3}}}}
aaa = 'bbb'
I need to import files like this, then unpack values, that are inside it only:
I do use:
imp.load_source('foo', r'<path_to_foo>\foo.py')
...and I am stuck here :( How to get an output with 'TL' and 'aaa' with their vlues?
2 Answers 2
You realy needed dynamicly load module? I think you just need
import foo
print(foo.TL)
print(foo.aaa)
If <path_to_foo> isn't package. You can do before import
import sys
sys.path.append(<path_to_foo>)
If you need dynamic import. Probably you can make
foo = imp.load_source('foo', r'<path_to_foo>\foo.py')
print(foo.TL)
print(foo.aaa)
1 Comment
What I was looking for was vars():
print(var) for var in vars(module)
What is yet unknown to me i s how to reduce depth to 1, (if imported module also imports modules, I don't want to see their vars)