Re: 动态生成函数

cafeeee <[email protected]>
Newsgroups gmane.comp.python.chinese
Message-ID <[email protected]>
用闭包可以解决这个问题:

>>> def s(param): print param
...
>>> m={"a":1, "b":2, "c": None}
>>> for k,v in m.items():
...     def ss(param=v): s(param)
...     locals()[k] = ss
...
>>> a()
1
>>> b()
2
>>> c()
None
>>>

_______________________________________________
python-chinese
Post: send [email protected]
Subscribe: send subscribe to [email protected]
Unsubscribe: send unsubscribe to  [email protected]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.