WEB开发网
开发学院软件开发Python Python 自省指南 - 如何监视您的 Python 对象 阅读

Python 自省指南 - 如何监视您的 Python 对象

 2007-03-30 12:34:10 来源:WEB开发网   
核心提示: 清单 1. 以交互方式启动 Python 解释器$ pythonPython 2.2.2 (#1, Oct 28 2002, 17:22:19)[GCC 3.2 (Mandrake Linux 9.0 3.2-1mdk)] on linux2Type "help", &

清单 1. 以交互方式启动 Python 解释器

$ python
Python 2.2.2 (#1, Oct 28 2002, 17:22:19)
[GCC 3.2 (Mandrake Linux 9.0 3.2-1mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

在让 Python 运行起来,并看到 Python 提示符( >>> )之后,您可能想知道 Python 能识别什么字。大多数编程语言都有保留字或关键字,这些字在该语言中有特殊的意义,Python 也不例外。您可能还注意到,Python 建议我们输入 help 以获取更多信息。也许我们可以向 Python 寻求一些关于关键字的帮助。

Python 的联机帮助实用程序

让我们按建议的那样,通过输入 help 来开始讨论,并观察它是否会向我们提供任何关于关键字的线索:

清单 2. 向 Python 寻求帮助

>>> help
Type help() for interactive help, or help(object) for help about object.

因为我们不知道哪些对象可能包含关键字,所以不指定任何特定对象来尝试 help() :

清单 3. 启动帮助实用程序

>>> help()
Welcome to Python 2.2! This is the online help utility.
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".
help>

上一页  1 2 3 4 5 6 7  下一页

Tags:

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接