摘要: 对于三目运算符(ternary operator),python可以用conditional expressions来替代如对于x<5?1:0可以用下面的方式来实现1 if x<5 else 0注: conditional expressions是在python 2.5之前引入的,所以以上代码仅适用于2.5以及之后的版本对于2.5之前的版本,可以用下面这种形式X<5 and 1 or 0对于switch,我们完全可以用dictionary来实现,看下面的例子>>> def switch(choice): return dict(enumerate(range 阅读全文
posted @ 2011-06-15 11:05 john2000 阅读(2872) 评论(0) 推荐(0) 编辑
摘要: 通过os.access(filename,mode):s.access(path, mode)¶Use the real uid/gid to test for access to path. Note that most operationswill use the effective uid/gid, therefore this routine can be used in asuid/sgid environment to test if the invoking user has the specified access topath. mode should be F_O 阅读全文
posted @ 2011-06-15 10:53 john2000 阅读(2299) 评论(0) 推荐(0) 编辑