python 自学入门:帮助系统

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hejinjing_tom_com/article/details/82081454

python 自学入门:帮助系统
============================================================
1. python 中使用的保留字是什么?
============================================================
每种语言都会有保留字的.如下来学习.
a. 准备环境
$sudo apt-get install python
$python --version
Python 2.7.6

$python -h
有一些简单的help信息
$man python
浏览一下就可以了,解释了命令行选项及环境变量等,不过提到用pydoc可以查看模块和包信息

b. 进入交互模式吧!
$python
我们看到,help 就是帮助提示
--------------------
In [4]: help()
help> keywords
--------------------
Here is a list of the Python keywords.  Enter any keyword to get more help.

and                 elif                if                  print
as                  else                import              raise
assert              except              in                  return
break               exec                is                  try
class               finally             lambda              while
continue            for                 not                 with
def                 from                or                  yield
del                 global              pass                
help 还提示我们输入topics 和 modules, 看一下就可以了.

------------------------------------------------------------
可以简化直接用 help('if') 来查看'if'关键字的描述
------------------------------------------------------------

============================================================
2. 我想知道python 内置的函数都有哪些?
============================================================
例如除了 hex 还有哪些内置函数?
help(hex)
Help on built-in function hex in module __builtin__:

hex(...)
    hex(number) -> string
    
    Return the hexadecimal representation of an integer or long integer.
(END)
help('__builtin__')
哇! 一下子输出了长长的文档,和man 手册的格式类似.太长,我们把它导成文件吧,
依靠python 解释器及命令行参数
$ python -c "help('__builtin__') > 1.man
$ vim 1.man
你就可以浏览了.
是的,我们看到了很多信息,可分为三类CLASSES,FUNCTIONS,DATA
功能中看到了熟悉的
abs(...)
chr(...)
cmp(...)
dir(...)
eval(...)
format(...)
hex(...)
input(...)
len(...)
max(...)
min(...)
range(...)
raw_input(...)
open(...)
print(...)
sorted(...)
其它我们就不列出了,反正有手册呢。
dir(...) 能够列出对象的属性信息,例如类成员,或成员函数列表,那就试试吧
dir()
--------------------
dir(__builtin__)
--------------------
直接用命令行python -c "cmd" 方式出了点问题,干脆我们写程序导出输出吧!.
f=file("./1.txt","w")
a=dir(__builtin__)
print >>f,a
f.close()

dir() 可付给变量,但help()不能付给变量, why? ...
其实也不必大费干戈来输出帮助.
在文档帮助方面,pydoc 无疑是另一个有用的帮助工具。
$ pydoc file
--------------------
$ pydoc __builtin__
--------------------
你能够得到你想要得!

猜你喜欢

转载自blog.csdn.net/hejinjing_tom_com/article/details/82081454
今日推荐