1、背景2、示例
1、背景我们写的脚本可能会考虑在windows以及linux的不同。
即允许根据代码运行的操作系统运行不同的代码。
python模块的os.name返回当前操作系统的类型,
可能会返回posix , nt , java, 分别对应linux/windows/java虚拟机!
在windows下:
C:UsersAdministrator>python Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.name 'nt' >>>
在linux下:
(base) root@iZuf63978tmw06cpq8okr2Z:~# python Python 3.7.6 (default, Jan 8 2020, 19:59:22) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.name 'posix' >>>



