Quantcast
Channel: 葡萄成熟时 » Glory Wu
Viewing all articles
Browse latest Browse all 20

《Dive into Python》Chapter 4 笔记

$
0
0

自省:Python中万物皆对象,自省是指代码可以查看内存中以对象形式存在的其它模块和函数,获取它们的信息,并对它们进行操作。用这种方法,可以定义没有名称的函数,不按函数声明的参数顺序调用函数,甚至引用事先不知道名称的函数。

Example 4.1 apihelper.py

def info(object, spaci ng=10, col lapse=1): 
"""Print methods and doc strings.

Takes module, class, l ist, dictionary, o r string."""
methodList = [method for method in dir(object) if callable(getattr(object, method))]
processFunc = collapse and (lambda s: " "[......]

继续阅读


Viewing all articles
Browse latest Browse all 20

Trending Articles