1.dir()
dir() 函数一个排好序的字符串列表,内容是一个模块里定义过的名字。
返回的列表容纳了在一个模块里定义的所有模块,变量和函数
1.1 dir 示例
定义一个模块
#coding-utf-8; def sum(a=1,b=2): print a+b; print "11";
模块引用:
#coding=utf-8; from mokuai_test import sum; import os; import math print dir(sum()); print dir(); print dir(sum);
结果输出:
11 3 ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'math', 'os', 'sum'] ['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']
标签:__,模块,python,sum,导入,func,print,dir From: https://www.cnblogs.com/joyware/p/16731183.html