使用dir(),help()查看查看对象的属性和文档
函数 描述 dir([obj]) 显示对象的属性,如果没有提供参数,则显示全局变量的名字 help([obj]) 以一种整齐美观的形式 显示对象的文档字符串,如果没有提供任何参数,则会进入交互式帮助。
sys 是与操作环境有关的函数。
以下我们用用dir()查看sys属性import sysprint dir(sys)
输出
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', '_mercurial', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'getwindowsversion', 'hexversion', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'py3kwarning', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions', 'winver']
选取几个进行说明
sys.argv 命令行参数List,第一个元素是程序本身路径 sys.path 是一个list,指明所有查找module,package的路径. 我的理解:这就是叫环境变量吧? sys.platform 得到运行的操作系统环境输入
import sysprint "The file name: ", sys.argv[0]print "The number of argument", len(sys.argv)print "The argument is: ", str(sys.argv)print "The platform is: ", str(sys.platform)
输出
D:/learnpython27/python27exercise.pyThe file name: D:/learnpython27/python27exercise.pyThe number of argument 1The argument is: ['D:/learnpython27/python27exercise.py']The platform is: win32 #这是什么鬼?我的不是win7吗
使用help()查看platform,得到
(话说,只能用help(sys) 然后再去找platform对应的说明吗?)platform -- platform identifier #平台识别符?不懂
还有很多,就不一一说明了(主要是没用过,说不出个所以然来)