Danny's profile季节的水滴PhotosBlogListsMore ![]() | Help |
|
5/27/2009 Python中and和or的特殊性质在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样。但是它们并不返回布尔值,而是返回它们实际进行比较的值之一。 2. or 介绍>>> 'a' or 'b' [1] 'a' >>> '' or 'b' [2] 'b' >>> '' or [] or {} [3] {} >>> def sidefx(): ... print "in sidefx()" ... return 1 >>> 'a' or sidefx() [4] 'a'
如果你是一名 C 语言黑客,肯定很熟悉 bool ? a : b 表达式,如果 bool 为真,表达式演算值为 a,否则为 b。基于 Python 中 and 和 or 的工作方式,你可以完成相同的事情。
3. and-or 技巧介绍>>> a = "first" >>> b = "second" >>> 1 and a or b {1} 'first' >>> 0 and a or b {2} 'second' 然而,由于这种 Python 表达式单单只是进行布尔逻辑运算,并不是语言的特定构成,这是 and-or 技巧和 C 语言中的 bool ? a : b 语法非常重要的不同。如果 a 为假,表达式就不会按你期望的那样工作了。(你能知道我被这个问题折腾过吗?不止一次?) 4. and-or 技巧无效的场合>>> a = "" >>> b = "second" >>> 1 and a or b (1) 'second'
and-or 技巧,也就是 bool and a or b 表达式,当 a 在布尔环境中的值为假时,不会像 C 语言表达式 bool ? a : b 那样工作。 在 and-or 技巧后面真正的技巧是,确保 a 的值决不会为假。最常用的方式是使 a 成为 [a] 、 b 成为 [b],然后使用返回值列表的第一个元素,应该是 a 或 b中的某一个。 5. 安全使用 and-or 技巧>>> a = "" >>> b = "second" >>> (1 and [a] or [b])[0] <1> ''
到现在为止,这个技巧可能看上去问题超过了它的价值。毕竟,使用 if 语句可以完成相同的事情,那为什么要经历这些麻烦事呢?哦,在很多情况下,你要在两个常量值中进行选择,由于你知道 a 的值总是为真,所以你可以使用这种较为简单的语法而且不用担心。对于使用更为复杂的安全形式,依然有很好的理由要求这样做。例如,在 Python 语言的某些情况下 if 语句是不允许使用的,比如在 lambda 函数中。
Python Cookbook 讨论了其它的 and-or 技巧。 《Dive Into Python》 http://diveintopython.org (英文原版) 和 http://www.woodpecker.org.cn/diveintopython(中文版) 5/13/2009 Windows下如何得到一个站点的IPC:\>ping mail.163.com
Pinging mcache.idns.yeah.net [123.125.50.22] with 32 bytes of datas:
C:\>nslookup mail.163.com
Server: bogon.cn.bl.medicel.com
Address: 192.168.9.10 Non-authoritative answer: Name: mcache.idns.yeah.net Address: 123.125.50.22 Aliases: mail.163.com, mcache.mail.163.com 5/12/2009 The Scrum Development ProcessOther useful website about Scrum:
There has a book you can download for free:Scrum and XP from the Trenches
You can get more information about the auther: Henrik Kniberg, and his blog is: http://blog.crisp.se/henrikkniberg 5/10/2009 Windows快速关机工具DirectShutDownDirectShutDown是一款免费和高可靠性的可以提供快速关机、重启、锁定、进入睡眠状态的工具;
DirectShutDown支持Windows98, Windows ME, Windows 2000, Windows XP,但是不支持Linux, Mac, Palm, or PocketPC;
点击链接下载:DirectShutDown
5/5/2009 微软开始提供Windows7 RC版下载1.下载日期持续到09年7月;
2.本次下载的用户可以免费使用到10年6月1日,从10年7月1日起安装此版本的电脑将会每隔两个小时自动关机一次,完全无法使用的时间为8月1日;
3.对PC硬件的要求:
5/1/2009 CMMI:Process Areas as Presented in the Continuous RepresentationProcess Management
OPF Organizational Process Focus
OPD Organizational Process Definition
OT Organizational Training
OPP Organizational Process Performance
OID Organizational Innovation and Deplotment
Project Management
PP Project Planning
PMC Project Monitoring and Control
SAM Supplier Agreement Management
IPM Integrated Project Management
RSKM Risk Management
IT Integrated Teaming
ISM Integrated Supplier Management
QPM Quantitative Project Management
Engineering
REQM Requirements Management
RD Requirements Development
TS Technical Solution
PI Product Integration
VER Verification
VAL Validation
Support
CM Configuration Management
PPQA Process and Product Quality Assurance
MA Measurement and Analysis
DAR Decision Analysis and Resolution
OEI Organizational Environment for Integration
CAR Causal Analysis and Resolution |
|
|