2
我想動態加載一個python文件並檢索它的變量。奇怪的未定義變量python3
這裏是我的代碼:
test_files = glob.glob("./test/*.py")
for test_file in test_files:
exec(open(test_file).read())
print(dir())
print(test_list)
test_file
是共享變量我想要檢索。
print(dir())
顯示:['test_file', 'test_files', 'test_list']
因此test_list
存在。
後的行:
print(test_list)
顯示回溯:
NameError: name 'test_list' is not defined
我錯過了什麼?
這是一個功能呢? –
是的,這裏是我所有的代碼:http://pastie.org/9983986 – Epitouille