06 2011 档案

摘要:判断一个callable对象是否是函数>>> import os>>> import types>>> >>> for item in dir(os): if isinstance(eval('.'.join(['os', item])), types.FunctionType): print item _execvpe_exists_get_exports_list_make_stat_result_make_statvfs_result_pickle_stat_result_pickle 阅读全文
posted @ 2011-06-24 10:35 john2000 阅读(375) 评论(0) 推荐(0)
摘要:对于三目运算符(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 阅读(2887) 评论(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 阅读(2319) 评论(0) 推荐(0)
摘要:http://www.lfd.uci.edu/~gohlke/pythonlibs/ 阅读全文
posted @ 2011-06-13 13:10 john2000 阅读(308) 评论(0) 推荐(0)
摘要:>>> l=range(3)>>> t=(3,4,5)>>> l[0, 1, 2]>>> t(3, 4, 5)>>> l.extend(t)>>> l[0, 1, 2, 3, 4, 5]>>> l+=t>>> l[0, 1, 2, 3, 4, 5, 3, 4, 5]看来list对象的+=操作和extend方法有异曲同工之处.如果我们直接l+t,就会报错,因为+不会对不同类型的object进行操作.>>> l+tTraceback (m 阅读全文
posted @ 2011-06-09 10:55 john2000 阅读(1149) 评论(0) 推荐(0)