zoukankan      html  css  js  c++  java
  • sys模块

    使用dir(),help()查看查看对象的属性和文档

    函数            描述 
    dir([obj])      显示对象的属性,如果没有提供参数,则显示全局变量的名字 
    help([obj])     以一种整齐美观的形式 显示对象的文档字符串,如果没有提供任何参数,则会进入交互式帮助。

    sys 是与操作环境有关的函数。
    以下我们用用dir()查看sys属性

    import sys
    print 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 sys
    
    print "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.py
    The file name:  D:/learnpython27/python27exercise.py
    The number of argument 1
    The argument is:  ['D:/learnpython27/python27exercise.py']
    The platform is:  win32  #这是什么鬼?我的不是win7吗

    使用help()查看platform,得到
    (话说,只能用help(sys) 然后再去找platform对应的说明吗?)

    platform -- platform identifier #平台识别符?不懂

    还有很多,就不一一说明了(主要是没用过,说不出个所以然来)

  • 相关阅读:
    MySQL数据库的完全备份与恢复
    MySQL数据库之索引、事务、存储引擎详细讲解
    LNMP架构介绍与部署
    Haproxy搭建Web集群
    LAMP环境之MySQL服务安装详细过程
    MySQL主从复制详解
    LAMP环境之编译安装httpd服务
    搭建yum软件仓库,让你维护轻松自如
    Shell脚本一键安装Samba服务
    Shell脚本之冒泡排序
  • 原文地址:https://www.cnblogs.com/jeff-ideas/p/10540353.html
Copyright © 2011-2022 走看看