使用方法很简单,举os类型为例,在Python命令窗口输入 dir(‘os’) 即可查看os模块的属性
打开cmd命令窗口:
2.如何查看对象某个属性的帮助文档:两种方法如下:
3.如何查看某个对象的详细:
3.如何查看某个对象的函数:
在 python 官网下载 Gzipped source tar ball, 解压缩后, 会发现 Lib/os.py 文件这行代码from posix import *
可是没有文件叫 posix.py 啊, 到底在那 ? 其实 posix module 是 builtin 的其中一分子,如下示范:
>>>import sys
>>>print sys.builtin_module_names
(*__builtin__*, *__main__*, *_ast*, *_codecs*, *_sre*, *_symtable*, *_warnings*, *_weakref*, *errno*, *exceptions*, *gc*, *imp*, *marshal*, *posix*, *pwd*, *signal*, *sys*, *thread*, *zipimport*)
>>>
所以要去 Modules 目录查找 c 代码, 你会看见 posixmodule.c, 打开它看见这行代码:
{"listdir", posix_listdir, METH_VARARGS, posix_listdir__doc__},
再寻找上面所得到的 posix_listdir method, 可以找到 listdir 源代码:
static PyObject *
posix_listdir(PyObject *self, PyObject *args)
{
/* XXX Should redo this putting the (now four) versions of opendir
in separate files instead of having them all here... */
#if defined(MS_WINDOWS) &&!defined(HAVE_OPENDIR)
PyObject *d, *v
HANDLE hFindFile
BOOL result
python获取命令行参数的方法:getopt模和argparse模块。getopt模块主要用到了模块中的函数:options, args = getopt.getopt(args, shortopts, longopts=[])
argparse模块用于解析命令行选项和参数的标准模块。
使用步骤:
1、import argparse#导入模块
2、parser = argparse.ArgumentParser()#创建解析对象
3、 parser.add_argument()#向该对象中添加使用到的命令行选项和参数
4、 parser.parser_args()#解析命令行