lambda中多行语句
Jiahua Huang <[email protected]> reply-to [email protected] to python-cn <[email protected]> date Sun, Jun 21, 2009 at 23:41
subject [CPyUG:90225] [http://groups.google.com/group/python-cn/browse_thread/thread/53c618c8309f95b4 凑合解决 lambda 里的多行语句和 print] - python-cnCPyUG华蟒用户组(中文Py用户组) | Google 网上论坛
样例
多说无益,
>>> import sys >>> myprint = lambda i: sys.stdout.write(str(i) + '\n') >>> foo = lambda i: not not ( ... myprint(i), ... myprint(i+1), ... myprint(i+2), ... myprint(i+3), ... ) >>> foo(1) 1 2 3 4 True
用途
嗯,缘由是为了让 gjots 等纯 PyGtk 程序支持 Undo/Redo 操作,
0. GtkTextView 默认不支持 Undo/Redo 操作,编辑区写错了很麻烦。 1. 不想再写 UndoBuffer ,于是简单用 GtkSourceView 代替 GtkTextView, 2. 为了编辑区切换文章后能处理好 UndoStack,需要处理 .set_text() 3. 为了不派生新类和嵌套函数,希望多个动作能放在一个 lambda 里 于是就凑合了个伪多行 lambda 4. 同时希望不修改旧的 glade 文件 于是就搬出了 override
过程见附件 gjots2 补丁
- attachment:gjots2-undo-support.patch
反馈
创建 by -- ZoomQuiet [DateTime(2009-06-21T16:03:48Z)]