Danny's profile季节的水滴PhotosBlogListsMore Tools Help

Blog


    5/31/2009

    eclipse的提示功能不见了怎么办

    windows->preference->java->Editor->content Assist->Advance
    5/27/2009

    Python中and和or的特殊性质

    Python 中,andor 执行布尔逻辑演算,如你所期待的一样。但是它们并不返回布尔值,而是返回它们实际进行比较的值之一。

    1. and 介绍

    >>> 'a' and 'b'         (1)
    'b'
    >>> '' and 'b'          (2)
    ''
    >>> 'a' and 'b' and 'c' (3)
    'c'
    (1) 使用 and 时,在布尔环境中从左到右演算表达式的值。0''[](){}None 在布尔环境中为假;其它任何东西都为真。还好,几乎是所有东西。默认情况下,布尔环境中的类实例为真,但是你可以在类中定义特定的方法使得类实例的演算值为假。你如果布尔环境中的所有值都为真,那么 and 返回最后一个值。在这个例子中,and 演算 'a' 的值为真,然后是 'b' 的演算值为真,最终返回 'b'
    (2) 如果布尔环境中的某个值为假,则 and 返回第一个假值。在这个例子中,'' 是第一个假值。
    (3)

    所有值都为真,所以 and 返回最后一个真值,'c'

    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'
    [1] 使用 or 时,在布尔环境中从左到右演算值,就像 and 一样。如果有一个值为真,or 立刻返回该值。本例中,'a' 是第一个真值。
    [2] or 演算 '' 的值为假,然后演算 'b' 的值为真,于是返回 'b'
    [3] 如果所有的值都为假,or 返回最后一个假值。or 演算 '' 的值为假,然后演算 [] 的值为假,依次演算 {} 的值为假,最终返回 {}
    [4] 注意 or 在布尔环境中会一直进行表达式演算直到找到第一个真值,然后就会忽略剩余的比较值。如果某些值具有副作用,这种特性就非常重要了。在这里,函数 sidefx 永远都不会被调用,因为 or 演算 'a' 的值为真,所以紧接着就立刻返回 'a' 了。

    如果你是一名 C 语言黑客,肯定很熟悉 bool ? a : b 表达式,如果 bool 为真,表达式演算值为 a,否则为 b。基于 Pythonandor 的工作方式,你可以完成相同的事情。

    • 使用 and-or 技巧

    3. and-or 技巧介绍

    >>> a = "first"
    >>> b = "second"
    >>> 1 and a or b {1}
    'first'
    >>> 0 and a or b {2}
    'second'
    
    {1}  这个语法看起来类似于 C 语言中的 bool ? a : b 表达式。整个表达式从左到右进行演算,所以先进行 and 表达式的演算。1 and 'first' 演算值为 'first',然后 'first' or 'second' 的演算值为 'first'
    {2} 0 and 'first' 演算值为 False,然后 0 or 'second' 演算值为 'second'

    然而,由于这种 Python 表达式单单只是进行布尔逻辑运算,并不是语言的特定构成,这是 and-or 技巧和 C 语言中的 bool ? a : b 语法非常重要的不同。如果 a 为假,表达式就不会按你期望的那样工作了。(你能知道我被这个问题折腾过吗?不止一次?)

    4. and-or 技巧无效的场合

    >>> a = ""
    >>> b = "second"
    >>> 1 and a or b         (1)
    'second'
    (1) 由于 a 是一个空字符串,在 Python 的布尔环境中空字符串被认为是假的,1 and '' 的演算值为 '',最后 '' or 'second' 的演算值为 'second'。噢!这个值并不是你想要的。

    and-or 技巧,也就是 bool and a or b 表达式,当 a 在布尔环境中的值为假时,不会像 C 语言表达式 bool ? a : b 那样工作。

    and-or 技巧后面真正的技巧是,确保 a 的值决不会为假。最常用的方式是使 a 成为 [a]b 成为 [b],然后使用返回值列表的第一个元素,应该是 ab中的某一个。

    5. 安全使用 and-or 技巧

    >>> a = ""
    >>> b = "second"
    >>> (1 and [a] or [b])[0] <1>
    ''
    <1> 由于 [a] 是一个非空列表,所以它决不会为假。即使 a0 或者 '' 或者其它假值,列表 [a] 也为真,因为它有一个元素。

    到现在为止,这个技巧可能看上去问题超过了它的价值。毕竟,使用 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下如何得到一个站点的IP

    C:\>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 Process

     
    Other 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快速关机工具DirectShutDown

    DirectShutDown是一款免费和高可靠性的可以提供快速关机、重启、锁定、进入睡眠状态的工具;
    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硬件的要求:
    • 1 GHz 或更高的 32-bit (x86) or 64-bit (x64) 处理器

    • 1 GB RAM (32-bit) / 2 GB RAM (64-bit)

    • 16 GB (32-bit) / 20 GB (64-bit) 可用硬盘空间

    • DirectX 9 图像处理器 with WDDM 1.0 or higher driver

    5/1/2009

    CMMI:Process Areas as Presented in the Continuous Representation

    Process 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