pyd文件是什么(pyd文件是什么文件)

pyd文件是什么(pyd文件是什么文件)p id 2MNVK98A 1 简介 p p id 2MNVK98B sys 模块主要负责与 Python 解释器进行交互 该模块提供了一系列用于控制 Python 运行环境的函数和变量 p p id 2MNVK98C 之前我们说过 os 模块 p

大家好,我是讯享网,很高兴认识大家。



 <p id="2MNVK98A">1. 简介</p><p id="2MNVK98B">sys 模块主要负责与 Python 解释器进行交互,该模块提供了一系列用于控制 Python 运行环境的函数和变量。</p><p id="2MNVK98C">之前我们说过os 模块,该模块与 sys 模块从名称上看着好像有点类似,实际上它们之间是没有什么关系的,os 模块主要负责与操作系统进行交互。</p><p id="2MNVK98D">2. 使用</p><p id="2MNVK98E">我们先整体看一下 sys 模块都包含哪些内容,如下所示:</p><p id="2MNVK98F">&gt;&gt;&gt; import sys&gt;&gt;&gt; dir(sys)['__displayhook__', '__doc__', '__excepthook__', '__interactivehook__', '__loader__', '__name__', '__package__', '__spec__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_debugmallocstats', '_enablelegacywindowsfsencoding', '_getframe', '_git', '_home', '_xoptions', 'api_version', 'argv', 'base_exec_prefix', 'base_prefix', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_info', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'get_asyncgen_hooks', 'get_coroutine_wrapper', 'getallocatedblocks', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencodeerrors', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace', 'getwindowsversion', 'hash_info', 'hexversion', 'implementation', 'int_info', 'intern', 'is_finalizing', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'set_asyncgen_hooks', 'set_coroutine_wrapper', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'version', 'version_info', 'warnoptions', 'winver']</p><p id="2MNVK98G">对于一些相对常用的变量和函数,我们下面再来具体看一下。</p><p id="2MNVK98H">argv</p><p id="2MNVK98I">返回传递给 Python 脚本的命令行参数列表。看下示例:</p><p id="2MNVK98J">import sysif __name__ == '__main__': args = sys.argv print(args) print(args[1])</p><p id="2MNVK98K">上面文件名为:test.py,我们在控制台使用命令:执行一下,执行结果如下:</p><p id="2MNVK98L">python test.py 123 abc</p><p id="2MNVK98M">['test.py', '123', 'abc']123</p><p id="2MNVK98N">version</p><p id="2MNVK98O">返回 Python 解释器的版本信息。</p><p id="2MNVK98P">winver</p><p id="2MNVK98Q">返回 Python 解释器主版号。</p><p id="2MNVK98R">platform</p><p id="2MNVK98S">返回操作系统平台名称。</p><p id="2MNVK98T">path</p><p id="2MNVK98U">返回模块的搜索路径列表。</p><p id="2MNVK98V">maxsize</p><p id="2MNVK990">返回支持的最大整数值。</p><p id="2MNVK991">maxunicode</p><p id="2MNVK992">返回支持的最大 Unicode 值。</p><p id="2MNVK993">copyright</p><p id="2MNVK994">返回 Python 版权信息。</p><p id="2MNVK995">modules以字典类型返回系统导入的模块。</p><p id="2MNVK996">byteorder</p><p id="2MNVK997">返回本地字节规则的指示器。</p><p id="2MNVK998">executable</p><p id="2MNVK999">返回 Python 解释器所在路径。</p><p id="2MNVK99A">import sysprint(sys.version)print(sys.winver)print(sys.platform)print(sys.path)print(sys.maxsize)print(sys.maxunicode)print(sys.copyright)print(sys.modules)print(sys.byteorder)print(sys.executable)</p><p id="2MNVK99B">stdout</p><p id="2MNVK99C">标准输出。看下示例:</p><p id="2MNVK99D">import sys# 下面两行代码等价sys.stdout.write('Hi' + ' 

讯享网

’)print(‘Hi’)

stdin

标准输入。看下示例:

import syss1 = input()s2 = sys.stdin.readline()print(s1)print(s2)

stderr

错误输出。看下示例:

import syssys.stderr.write(‘this is a error message’)

exit()


讯享网

退出当前程序。看下示例:

import sysprint(‘Hi’)sys.exit()print(‘Jhon’)

getdefaultencoding()

返回当前默认字符串编码的名称。

getrefcount(obj)

返回对象的引用计数。

getrecursionlimit()

返回支持的递归深度。

getsizeof(object[, default])

以字节为单位返回对象的大小。

setswitchinterval(interval)

设置线程切换的时间间隔。

getswitchinterval()

返回线程切换时间间隔。

import sysprint(sys.getdefaultencoding())print(sys.getrefcount(‘’))print(sys.getrecursionlimit())print(sys.getsizeof(‘abcde’))sys.setswitchinterval(1)print(sys.getswitchinterval())



小讯
上一篇 2025-04-24 14:56
下一篇 2025-04-18 22:45

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/201432.html