[译]三个有用的python方法:dir, help 和 pprint
Python提供了三个方便的函数,可以使我们直接从解释器中就获得对象的文档。
dir- 列出一个对象的所有方法和属性help- 用来显示文档pprint- 非常棒的一个打印库,可以将对象的内容用易阅读的格式打印出来
下面的例子能让你更清楚它们的使用:
PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39)...
>>> import string
>>> dir(string)
['_StringType', '__builtins__', '__doc__',...]
>>> help(string)
Help on module string:
NAME
string - A collection of string operations (most are no longer used in Python 1.6).
FILE
d:\python22\lib\string.py
DESCRIPTION
Warning: most of the code you see here isn’t normally used nowadays. With
Python 1.6, many of these functions are implemented as methods on the
standard string object.
...
>>> from pprint import pprint
>>> pprint(dir(string))
['_StringType',
'__builtins__',
'__doc__',
'__file__',
...
简单且方便,不是吗?
本文翻译并转载自这里。

九月 29th, 2008 at 18:31
看看头像
五月 28th, 2009 at 02:56
bpKFg, utnff , [url=http://www.autoe4hml5a.com]5p3ld[/url], http://www.ihuxsbtjuvg.com edyhat