sys.platform中可能的值?

2024-05-21 03:29:35 发布

您现在位置:Python中文网/ 问答频道 /正文

以下命令可能返回的值是什么?

import sys
print sys.platform

我知道有很多可能性,所以我主要对“主要”的(Windows、Linux、Mac OS)感兴趣


Tags: import命令oslinuxwindowsmacsys可能性
3条回答

Mac OS X(10.4、10.5、10.7、10.8版):

darwin

Linux(2.6内核):

linux2

Windows XP 32位:

win32

括号中的版本已被选中-其他/较新版本可能相同。

As others have indicated, sys.platform is derived from the name that the system vendor gives their system. However, Python also adds plat- to sys.path, so you can look at all the plat-* directories in the Python distribution.

This gives you the list

aix3 aix4 atheos beos5 darwin freebsd2 freebsd3 freebsd4 freebsd5 freebsd6 freebsd7 generic irix5 irix6 linux2 mac netbsd1 next3 os2emx riscos sunos5 unixware7

Of course, sys.platform can have additional values, when Python gets compiled on a system for which no platform-specific directory has been created.

来自here

┍━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━┑
│ System              │ Value               │
┝━━━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━┥
│ Linux               │ linux or linux2 (*) │
│ Windows             │ win32               │
│ Windows/Cygwin      │ cygwin              │
│ Windows/MSYS2       │ msys                │
│ Mac OS X            │ darwin              │
│ OS/2                │ os2                 │
│ OS/2 EMX            │ os2emx              │
│ RiscOS              │ riscos              │
│ AtheOS              │ atheos              │
│ FreeBSD 7           │ freebsd7            │
│ FreeBSD 8           │ freebsd8            │
│ FreeBSD N           │ freebsdN            │
│ OpenBSD 6           │ openbsd6            │
┕━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━┙

(*)在Python 3.3之前,任何Linux版本的值总是linux2;之后,它是linux

相关问题 更多 >