Skip to main content

Python Python中的sys模块

Published 1 min readMarkdown
Python Python中的sys模块

Python中的sys模块

sys中的常用方法

函数名参数介绍举例返回值
modules无Py启动时加载的模块sys.modules( )列表
path无返回当前py的环境路径sys.path()列表
exitarg退出程序sys.exit(0)无
getdefaultencoding无获取系统编码sys.getdefaultencoding()字符串
platform无获取当前系统平台sys.platform()字符串
version(属性)无获取python版本sys.version字符串
argv*args程序外部获取参数sys.argv列表

代码

# coding:utf-8

import sys

command = sys.argv[1]
if command == 'modules':
    modules = sys.modules
    print(modules)
elif command == 'path':
# sys.exit(1)
    path = sys.path
    print(path)
elif command == 'encoding':
    code = sys.getdefaultencoding()
    print(code)
elif command == 'platform':
    print(sys.platform)
elif command == 'version':
    print(sys.version)
else:
    print('not command')

# print(sys.argv)

1 view

No comments yet. Be the first to comment.

More from this blog