2014-01-23 21 views
0

在python中運行代碼時我想更新config(全局變量)中的字典值我試圖做但我得到以下錯誤。如何在運行時爲python分配一個值到全局變量

config.py

survey={'url':''} 

runnigcode.py

url=config.__getattribute__(config.environment) 
url['url']='myurl.com' 

TypeError: "'module' object does not support item assignment" 
+0

如果你通過編輯你的問題來添加你的代碼會更好。 – Lafexlos

+0

添加了代碼。 – user3213909

+0

任何人都可以告訴我如何在運行時編輯全局變量 – user3213909

回答

0
在runningcode.py

,只是導入變量的方法:

from config import survey 

print survey 

,如果你想修改在config.py中的值,只需使用寫入方法,就像在這篇文章中一樣:Edit configuration file through python

相關問題