platform
— 访问底层平台的标识数据
¶
源代码: Lib/platform.py
注意
具体平台按字母顺序列出,Unix 部分包含 Linux。
platform.
architecture
(
executable=sys.executable
,
bits=''
,
linkage=''
)
¶
查询给定可执行文件 (默认为 Python 解释器二进制文件) 为各种体系结构信息。
返回元组
(bits, linkage)
其中包含可执行文件使用的位体系结构和链接格式的有关信息。两者值以字符串形式返回。
无法确定的值按预置参数给定方式返回。若 bits 给定为
''
,
sizeof(pointer)
(或
sizeof(long)
on Python version < 1.5.2) is used as indicator for the supported pointer size.
函数依赖系统
file
command to do the actual work. This is available on most if not all Unix platforms and some non-Unix platforms and then only if the executable points to the Python interpreter. Reasonable defaults are used when the above needs are not met.
注意
On Mac OS X (and perhaps other platforms), executable files may be universal files containing multiple architectures.
To get at the “64-bitness” of the current interpreter, it is more reliable to query the
sys.maxsize
属性:
is_64bits = sys.maxsize > 2**32
platform.
machine
(
)
¶
返回机器类型,如
'i386'
。返回空字符串若值无法确定。
platform.
node
(
)
¶
返回计算机的网络名称 (可能并非完全合格)。返回空字符串若值无法确定。
platform.
platform
(
aliased=0
,
terse=0
)
¶
返回标识底层平台,带有尽可能多有用信息的单字符串。
The output is intended to be human readable rather than machine parseable. It may look different on different platforms and this is intended.
若
aliased
is true, the function will use aliases for various platforms that report system names which differ from their common names, for example SunOS will be reported as Solaris. The
system_alias()
function is used to implement this.
设置 terse to true causes the function to return only the absolute minimum information needed to identify the platform.
platform.
processor
(
)
¶
返回 (真实) 处理器名称,如
'amdk6'
.
An empty string is returned if the value cannot be determined. Note that many platforms do not provide this information or simply return the same value as for
machine()
. NetBSD does this.
platform.
python_build
(
)
¶
返回元组
(buildno, builddate)
以字符串形式声明 Python 构建编号和日期。
platform.
python_compiler
(
)
¶
返回用于编译 Python 的编译器标识字符串。
platform.
python_branch
(
)
¶
返回 Python 实现 SCM 分支的标识字符串。
platform.
python_implementation
(
)
¶
返回 Python 实现标识字符串。可能的返回值,包括:CPython、IronPython、Jython、PyPy。
platform.
python_revision
(
)
¶
返回 Python 实现 SCM 修订标识字符串。
platform.
python_version
(
)
¶
返回 Python 版本如字符串
'major.minor.patchlevel'
.
注意,不像 Python
sys.version
,返回值将始终包括补丁级别 (默认为 0)。
platform.
python_version_tuple
(
)
¶
返回 Python 版本如元组
(major, minor, patchlevel)
按字符串。
注意,不像 Python
sys.version
, the returned value will always include the patchlevel (it defaults to
'0'
).
platform.
release
(
)
¶
返回系统的发行,如
'2.2.0'
or
'NT'
An empty string is returned if the value cannot be determined.
platform.
system
(
)
¶
Returns the system/OS name, e.g.
'Linux'
,
'Windows'
,或
'Java'
。返回空字符串若值无法确定。
platform.
system_alias
(
system
,
release
,
version
)
¶
返回
(system, release, version)
aliased to common marketing names used for some systems. It also does some reordering of the information in some cases where it would otherwise cause confusion.
platform.
version
(
)
¶
返回系统的发行版本,如
'#3 on degas'
。返回空字符串若值无法确定。
platform.
uname
(
)
¶
相当可移植的 uname 接口。返回
namedtuple()
包含 6 属性:
system
,
node
,
release
,
version
,
machine
,和
processor
.
注意,这添加的第 6 属性 (
processor
) 不会呈现在
os.uname()
result. Also, the attribute names are different for the first two attributes;
os.uname()
names them
sysname
and
nodename
.
Entries which cannot be determined are set to
''
.
3.3 版改变: 将结果从元组更改为命名元组。
platform.
java_ver
(
release=''
,
vendor=''
,
vminfo=(''
,
''
,
'')
,
osinfo=(''
,
''
,
'')
)
¶
用于 Jython 的版本接口。
返回元组
(release, vendor, vminfo, osinfo)
with
vminfo
是元组
(vm_name, vm_release, vm_vendor)
and
osinfo
是元组
(os_name, os_version, os_arch)
. Values which cannot be determined are set to the defaults given as parameters (which all default to
''
).
platform.
win32_ver
(
release=''
,
version=''
,
csd=''
,
ptype=''
)
¶
Get additional version information from the Windows Registry and return a tuple
(release, version, csd, ptype)
referring to OS release, version number, CSD level (service pack) and OS type (multi/single processor).
As a hint:
ptype
is
'Uniprocessor Free'
on single processor NT machines and
'Multiprocessor Free'
on multi processor machines. The
‘Free’
refers to the OS version being free of debugging code. It could also state
‘Checked’
which means the OS version uses debugging code, i.e. code that checks arguments, ranges, etc.
注意
This function works best with Mark Hammond’s
win32all
package installed, but also on Python 2.3 and later (support for this was added in Python 2.6). It obviously only runs on Win32 compatible platforms.
platform.
popen
(
cmd
,
mode='r'
,
bufsize=-1
)
¶
Portable
popen()
interface. Find a working popen implementation preferring
win32pipe.popen()
. On Windows NT,
win32pipe.popen()
should work; on Windows 9x it hangs due to bugs in the MS C library.
从 3.3 版起弃用:
This function is obsolete. Use the
subprocess
module. Check especially the
替换较旧函数采用 subprocess 模块
章节。
platform.
mac_ver
(
release=''
,
versioninfo=(''
,
''
,
'')
,
machine=''
)
¶
Get Mac OS version information and return it as tuple
(release, versioninfo,
machine)
with
versioninfo
是元组
(version, dev_stage,
non_release_version)
.
Entries which cannot be determined are set to
''
. All tuple entries are strings.
platform.
dist
(
distname=''
,
version=''
,
id=''
,
supported_dists=('SuSE'
,
'debian'
,
'redhat'
,
'mandrake'
,
...)
)
¶
This is another name for
linux_distribution()
.
Deprecated since version 3.5, will be removed in version 3.7.
platform.
linux_distribution
(
distname=''
,
version=''
,
id=''
,
supported_dists=('SuSE'
,
'debian'
,
'redhat'
,
'mandrake'
,
...)
,
full_distribution_name=1
)
¶
Tries to determine the name of the Linux OS distribution name.
supported_dists
may be given to define the set of Linux distributions to look for. It defaults to a list of currently supported Linux distributions identified by their release file name.
若
full_distribution_name
is true (default), the full distribution read from the OS is returned. Otherwise the short name taken from
supported_dists
被使用。
返回元组
(distname,version,id)
which defaults to the args given as parameters.
id
is the item in parentheses after the version number. It is usually the version codename.
Deprecated since version 3.5, will be removed in version 3.7.
platform.
libc_ver
(
executable=sys.executable
,
lib=''
,
version=''
,
chunksize=2048
)
¶
Tries to determine the libc version against which the file executable (defaults to the Python interpreter) is linked. Returns a tuple of strings
(lib,
version)
which default to the given parameters in case the lookup fails.
Note that this function has intimate knowledge of how different libc versions add symbols to the executable is probably only usable for executables compiled using gcc .
The file is read and scanned in chunks of chunksize 字节。