1
我有一些存儲在.txt文件中的屬性,這些屬性被多個模塊存儲的幾個不同的類和函數使用。爲了能夠從這些不同的位置訪問屬性,我有一個空白模塊。Python對ConfigParser的使用
將模塊本身設置爲ConfigParser對象還是讀入所有參數並將它們設置爲模塊級屬性會更好嗎?
I.e.來訪問參數時,第一種方式
blank_module = ConfigParser.ConfigParser()
blank_module.read("file.txt")
Then access with blank_module.get('section1', 'property1')
VS
local_var = ConfigParser.ConfigParser()
local_var.read("file.txt")
blank_module.property1 = local_var.get('section1', 'property1')
blank_module.property2 = local_var.get('section1', 'property2')
etc...
then access with blank_module.property1
第二種方法看起來更優雅,但我不能確定他們將如何在性能方面有所不同。