擅长:python、mysql、java
<p>我想你想要的只是给一个成员变量赋值,比如:</p>
<pre><code>class Foo(object):
pass
cfg = Foo()
cfg.item_i_want = "An item"
print cfg.item_i_want
</code></pre>
<p>这将打印“项目”。参见:<a href="http://ideone.com/LDz7NK" rel="nofollow">http://ideone.com/LDz7NK</a></p>
<p>如果要动态选择变量名,请使用<code>setattr(cfg, "another_item_i_want", "another item")</code>。在</p>