gooderp18绿色标准版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

633 linhas
47KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="platform — Access to underlying platform’s identifying data" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/platform.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/platform.py Cross Platform: Java Platform: Windows Platform: macOS Platform: Unix Platforms: Linux Platforms:" />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/platform.py Cross Platform: Java Platform: Windows Platform: macOS Platform: Unix Platforms: Linux Platforms:" />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>platform — Access to underlying platform’s identifying data &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="errno — Standard errno system symbols" href="errno.html" />
  33. <link rel="prev" title="curses.panel — A panel stack extension for curses" href="curses.panel.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/platform.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code> — Access to underlying platform’s identifying data</a><ul>
  86. <li><a class="reference internal" href="#cross-platform">Cross Platform</a></li>
  87. <li><a class="reference internal" href="#java-platform">Java Platform</a></li>
  88. <li><a class="reference internal" href="#windows-platform">Windows Platform</a></li>
  89. <li><a class="reference internal" href="#macos-platform">macOS Platform</a></li>
  90. <li><a class="reference internal" href="#unix-platforms">Unix Platforms</a></li>
  91. <li><a class="reference internal" href="#linux-platforms">Linux Platforms</a></li>
  92. </ul>
  93. </li>
  94. </ul>
  95. </div>
  96. <div>
  97. <h4>Previous topic</h4>
  98. <p class="topless"><a href="curses.panel.html"
  99. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses.panel</span></code> — A panel stack extension for curses</a></p>
  100. </div>
  101. <div>
  102. <h4>Next topic</h4>
  103. <p class="topless"><a href="errno.html"
  104. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">errno</span></code> — Standard errno system symbols</a></p>
  105. </div>
  106. <div role="note" aria-label="source link">
  107. <h3>This Page</h3>
  108. <ul class="this-page-menu">
  109. <li><a href="../bugs.html">Report a Bug</a></li>
  110. <li>
  111. <a href="https://github.com/python/cpython/blob/main/Doc/library/platform.rst"
  112. rel="nofollow">Show Source
  113. </a>
  114. </li>
  115. </ul>
  116. </div>
  117. </nav>
  118. </div>
  119. </div>
  120. <div class="related" role="navigation" aria-label="related navigation">
  121. <h3>Navigation</h3>
  122. <ul>
  123. <li class="right" style="margin-right: 10px">
  124. <a href="../genindex.html" title="General Index"
  125. accesskey="I">index</a></li>
  126. <li class="right" >
  127. <a href="../py-modindex.html" title="Python Module Index"
  128. >modules</a> |</li>
  129. <li class="right" >
  130. <a href="errno.html" title="errno — Standard errno system symbols"
  131. accesskey="N">next</a> |</li>
  132. <li class="right" >
  133. <a href="curses.panel.html" title="curses.panel — A panel stack extension for curses"
  134. accesskey="P">previous</a> |</li>
  135. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  136. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  137. <li class="switchers">
  138. <div class="language_switcher_placeholder"></div>
  139. <div class="version_switcher_placeholder"></div>
  140. </li>
  141. <li>
  142. </li>
  143. <li id="cpython-language-and-version">
  144. <a href="../index.html">3.12.3 Documentation</a> &#187;
  145. </li>
  146. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  147. <li class="nav-item nav-item-2"><a href="allos.html" accesskey="U">Generic Operating System Services</a> &#187;</li>
  148. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code> — Access to underlying platform’s identifying data</a></li>
  149. <li class="right">
  150. <div class="inline-search" role="search">
  151. <form class="inline-search" action="../search.html" method="get">
  152. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  153. <input type="submit" value="Go" />
  154. </form>
  155. </div>
  156. |
  157. </li>
  158. <li class="right">
  159. <label class="theme-selector-label">
  160. Theme
  161. <select class="theme-selector" oninput="activateTheme(this.value)">
  162. <option value="auto" selected>Auto</option>
  163. <option value="light">Light</option>
  164. <option value="dark">Dark</option>
  165. </select>
  166. </label> |</li>
  167. </ul>
  168. </div>
  169. <div class="document">
  170. <div class="documentwrapper">
  171. <div class="bodywrapper">
  172. <div class="body" role="main">
  173. <section id="module-platform">
  174. <span id="platform-access-to-underlying-platform-s-identifying-data"></span><h1><a class="reference internal" href="#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code></a> — Access to underlying platform’s identifying data<a class="headerlink" href="#module-platform" title="Link to this heading">¶</a></h1>
  175. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/platform.py">Lib/platform.py</a></p>
  176. <hr class="docutils" />
  177. <div class="admonition note">
  178. <p class="admonition-title">Note</p>
  179. <p>Specific platforms listed alphabetically, with Linux included in the Unix
  180. section.</p>
  181. </div>
  182. <section id="cross-platform">
  183. <h2>Cross Platform<a class="headerlink" href="#cross-platform" title="Link to this heading">¶</a></h2>
  184. <dl class="py function">
  185. <dt class="sig sig-object py" id="platform.architecture">
  186. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">architecture</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">executable</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">sys.executable</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bits</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">linkage</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#platform.architecture" title="Link to this definition">¶</a></dt>
  187. <dd><p>Queries the given executable (defaults to the Python interpreter binary) for
  188. various architecture information.</p>
  189. <p>Returns a tuple <code class="docutils literal notranslate"><span class="pre">(bits,</span> <span class="pre">linkage)</span></code> which contain information about the bit
  190. architecture and the linkage format used for the executable. Both values are
  191. returned as strings.</p>
  192. <p>Values that cannot be determined are returned as given by the parameter presets.
  193. If bits is given as <code class="docutils literal notranslate"><span class="pre">''</span></code>, the <code class="docutils literal notranslate"><span class="pre">sizeof(pointer)</span></code> (or
  194. <code class="docutils literal notranslate"><span class="pre">sizeof(long)</span></code> on Python version &lt; 1.5.2) is used as indicator for the
  195. supported pointer size.</p>
  196. <p>The function relies on the system’s <code class="file docutils literal notranslate"><span class="pre">file</span></code> command to do the actual work.
  197. This is available on most if not all Unix platforms and some non-Unix platforms
  198. and then only if the executable points to the Python interpreter. Reasonable
  199. defaults are used when the above needs are not met.</p>
  200. <div class="admonition note">
  201. <p class="admonition-title">Note</p>
  202. <p>On macOS (and perhaps other platforms), executable files may be
  203. universal files containing multiple architectures.</p>
  204. <p>To get at the “64-bitness” of the current interpreter, it is more
  205. reliable to query the <a class="reference internal" href="sys.html#sys.maxsize" title="sys.maxsize"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.maxsize</span></code></a> attribute:</p>
  206. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">is_64bits</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">maxsize</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="o">**</span><span class="mi">32</span>
  207. </pre></div>
  208. </div>
  209. </div>
  210. </dd></dl>
  211. <dl class="py function">
  212. <dt class="sig sig-object py" id="platform.machine">
  213. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">machine</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.machine" title="Link to this definition">¶</a></dt>
  214. <dd><p>Returns the machine type, e.g. <code class="docutils literal notranslate"><span class="pre">'AMD64'</span></code>. An empty string is returned if the
  215. value cannot be determined.</p>
  216. </dd></dl>
  217. <dl class="py function">
  218. <dt class="sig sig-object py" id="platform.node">
  219. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">node</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.node" title="Link to this definition">¶</a></dt>
  220. <dd><p>Returns the computer’s network name (may not be fully qualified!). An empty
  221. string is returned if the value cannot be determined.</p>
  222. </dd></dl>
  223. <dl class="py function">
  224. <dt class="sig sig-object py" id="platform.platform">
  225. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">platform</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">aliased</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">terse</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#platform.platform" title="Link to this definition">¶</a></dt>
  226. <dd><p>Returns a single string identifying the underlying platform with as much useful
  227. information as possible.</p>
  228. <p>The output is intended to be <em>human readable</em> rather than machine parseable. It
  229. may look different on different platforms and this is intended.</p>
  230. <p>If <em>aliased</em> is true, the function will use aliases for various platforms that
  231. report system names which differ from their common names, for example SunOS will
  232. be reported as Solaris. The <a class="reference internal" href="#platform.system_alias" title="platform.system_alias"><code class="xref py py-func docutils literal notranslate"><span class="pre">system_alias()</span></code></a> function is used to implement
  233. this.</p>
  234. <p>Setting <em>terse</em> to true causes the function to return only the absolute minimum
  235. information needed to identify the platform.</p>
  236. <div class="versionchanged">
  237. <p><span class="versionmodified changed">Changed in version 3.8: </span>On macOS, the function now uses <a class="reference internal" href="#platform.mac_ver" title="platform.mac_ver"><code class="xref py py-func docutils literal notranslate"><span class="pre">mac_ver()</span></code></a>, if it returns a
  238. non-empty release string, to get the macOS version rather than the darwin
  239. version.</p>
  240. </div>
  241. </dd></dl>
  242. <dl class="py function">
  243. <dt class="sig sig-object py" id="platform.processor">
  244. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">processor</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.processor" title="Link to this definition">¶</a></dt>
  245. <dd><p>Returns the (real) processor name, e.g. <code class="docutils literal notranslate"><span class="pre">'amdk6'</span></code>.</p>
  246. <p>An empty string is returned if the value cannot be determined. Note that many
  247. platforms do not provide this information or simply return the same value as for
  248. <a class="reference internal" href="#platform.machine" title="platform.machine"><code class="xref py py-func docutils literal notranslate"><span class="pre">machine()</span></code></a>. NetBSD does this.</p>
  249. </dd></dl>
  250. <dl class="py function">
  251. <dt class="sig sig-object py" id="platform.python_build">
  252. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">python_build</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.python_build" title="Link to this definition">¶</a></dt>
  253. <dd><p>Returns a tuple <code class="docutils literal notranslate"><span class="pre">(buildno,</span> <span class="pre">builddate)</span></code> stating the Python build number and
  254. date as strings.</p>
  255. </dd></dl>
  256. <dl class="py function">
  257. <dt class="sig sig-object py" id="platform.python_compiler">
  258. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">python_compiler</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.python_compiler" title="Link to this definition">¶</a></dt>
  259. <dd><p>Returns a string identifying the compiler used for compiling Python.</p>
  260. </dd></dl>
  261. <dl class="py function">
  262. <dt class="sig sig-object py" id="platform.python_branch">
  263. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">python_branch</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.python_branch" title="Link to this definition">¶</a></dt>
  264. <dd><p>Returns a string identifying the Python implementation SCM branch.</p>
  265. </dd></dl>
  266. <dl class="py function">
  267. <dt class="sig sig-object py" id="platform.python_implementation">
  268. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">python_implementation</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.python_implementation" title="Link to this definition">¶</a></dt>
  269. <dd><p>Returns a string identifying the Python implementation. Possible return values
  270. are: ‘CPython’, ‘IronPython’, ‘Jython’, ‘PyPy’.</p>
  271. </dd></dl>
  272. <dl class="py function">
  273. <dt class="sig sig-object py" id="platform.python_revision">
  274. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">python_revision</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.python_revision" title="Link to this definition">¶</a></dt>
  275. <dd><p>Returns a string identifying the Python implementation SCM revision.</p>
  276. </dd></dl>
  277. <dl class="py function">
  278. <dt class="sig sig-object py" id="platform.python_version">
  279. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">python_version</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.python_version" title="Link to this definition">¶</a></dt>
  280. <dd><p>Returns the Python version as string <code class="docutils literal notranslate"><span class="pre">'major.minor.patchlevel'</span></code>.</p>
  281. <p>Note that unlike the Python <code class="docutils literal notranslate"><span class="pre">sys.version</span></code>, the returned value will always
  282. include the patchlevel (it defaults to 0).</p>
  283. </dd></dl>
  284. <dl class="py function">
  285. <dt class="sig sig-object py" id="platform.python_version_tuple">
  286. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">python_version_tuple</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.python_version_tuple" title="Link to this definition">¶</a></dt>
  287. <dd><p>Returns the Python version as tuple <code class="docutils literal notranslate"><span class="pre">(major,</span> <span class="pre">minor,</span> <span class="pre">patchlevel)</span></code> of strings.</p>
  288. <p>Note that unlike the Python <code class="docutils literal notranslate"><span class="pre">sys.version</span></code>, the returned value will always
  289. include the patchlevel (it defaults to <code class="docutils literal notranslate"><span class="pre">'0'</span></code>).</p>
  290. </dd></dl>
  291. <dl class="py function">
  292. <dt class="sig sig-object py" id="platform.release">
  293. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">release</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.release" title="Link to this definition">¶</a></dt>
  294. <dd><p>Returns the system’s release, e.g. <code class="docutils literal notranslate"><span class="pre">'2.2.0'</span></code> or <code class="docutils literal notranslate"><span class="pre">'NT'</span></code>. An empty string is
  295. returned if the value cannot be determined.</p>
  296. </dd></dl>
  297. <dl class="py function">
  298. <dt class="sig sig-object py" id="platform.system">
  299. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">system</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.system" title="Link to this definition">¶</a></dt>
  300. <dd><p>Returns the system/OS name, such as <code class="docutils literal notranslate"><span class="pre">'Linux'</span></code>, <code class="docutils literal notranslate"><span class="pre">'Darwin'</span></code>, <code class="docutils literal notranslate"><span class="pre">'Java'</span></code>,
  301. <code class="docutils literal notranslate"><span class="pre">'Windows'</span></code>. An empty string is returned if the value cannot be determined.</p>
  302. </dd></dl>
  303. <dl class="py function">
  304. <dt class="sig sig-object py" id="platform.system_alias">
  305. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">system_alias</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">system</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">release</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">version</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#platform.system_alias" title="Link to this definition">¶</a></dt>
  306. <dd><p>Returns <code class="docutils literal notranslate"><span class="pre">(system,</span> <span class="pre">release,</span> <span class="pre">version)</span></code> aliased to common marketing names used
  307. for some systems. It also does some reordering of the information in some cases
  308. where it would otherwise cause confusion.</p>
  309. </dd></dl>
  310. <dl class="py function">
  311. <dt class="sig sig-object py" id="platform.version">
  312. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">version</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.version" title="Link to this definition">¶</a></dt>
  313. <dd><p>Returns the system’s release version, e.g. <code class="docutils literal notranslate"><span class="pre">'#3</span> <span class="pre">on</span> <span class="pre">degas'</span></code>. An empty string is
  314. returned if the value cannot be determined.</p>
  315. </dd></dl>
  316. <dl class="py function">
  317. <dt class="sig sig-object py" id="platform.uname">
  318. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">uname</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.uname" title="Link to this definition">¶</a></dt>
  319. <dd><p>Fairly portable uname interface. Returns a <a class="reference internal" href="collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a>
  320. containing six attributes: <a class="reference internal" href="#platform.system" title="platform.system"><code class="xref py py-attr docutils literal notranslate"><span class="pre">system</span></code></a>, <a class="reference internal" href="#platform.node" title="platform.node"><code class="xref py py-attr docutils literal notranslate"><span class="pre">node</span></code></a>, <a class="reference internal" href="#platform.release" title="platform.release"><code class="xref py py-attr docutils literal notranslate"><span class="pre">release</span></code></a>,
  321. <a class="reference internal" href="#platform.version" title="platform.version"><code class="xref py py-attr docutils literal notranslate"><span class="pre">version</span></code></a>, <a class="reference internal" href="#platform.machine" title="platform.machine"><code class="xref py py-attr docutils literal notranslate"><span class="pre">machine</span></code></a>, and <a class="reference internal" href="#platform.processor" title="platform.processor"><code class="xref py py-attr docutils literal notranslate"><span class="pre">processor</span></code></a>.</p>
  322. <p><a class="reference internal" href="#platform.processor" title="platform.processor"><code class="xref py py-attr docutils literal notranslate"><span class="pre">processor</span></code></a> is resolved late, on demand.</p>
  323. <p>Note: the first two attribute names differ from the names presented by
  324. <a class="reference internal" href="os.html#os.uname" title="os.uname"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.uname()</span></code></a>, where they are named <code class="xref py py-attr docutils literal notranslate"><span class="pre">sysname</span></code> and
  325. <code class="xref py py-attr docutils literal notranslate"><span class="pre">nodename</span></code>.</p>
  326. <p>Entries which cannot be determined are set to <code class="docutils literal notranslate"><span class="pre">''</span></code>.</p>
  327. <div class="versionchanged">
  328. <p><span class="versionmodified changed">Changed in version 3.3: </span>Result changed from a tuple to a <a class="reference internal" href="collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a>.</p>
  329. </div>
  330. <div class="versionchanged">
  331. <p><span class="versionmodified changed">Changed in version 3.9: </span><a class="reference internal" href="#platform.processor" title="platform.processor"><code class="xref py py-attr docutils literal notranslate"><span class="pre">processor</span></code></a> is resolved late instead of immediately.</p>
  332. </div>
  333. </dd></dl>
  334. </section>
  335. <section id="java-platform">
  336. <h2>Java Platform<a class="headerlink" href="#java-platform" title="Link to this heading">¶</a></h2>
  337. <dl class="py function">
  338. <dt class="sig sig-object py" id="platform.java_ver">
  339. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">java_ver</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">release</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">vendor</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">vminfo</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">('',</span> <span class="pre">'',</span> <span class="pre">'')</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">osinfo</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">('',</span> <span class="pre">'',</span> <span class="pre">'')</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#platform.java_ver" title="Link to this definition">¶</a></dt>
  340. <dd><p>Version interface for Jython.</p>
  341. <p>Returns a tuple <code class="docutils literal notranslate"><span class="pre">(release,</span> <span class="pre">vendor,</span> <span class="pre">vminfo,</span> <span class="pre">osinfo)</span></code> with <em>vminfo</em> being a
  342. tuple <code class="docutils literal notranslate"><span class="pre">(vm_name,</span> <span class="pre">vm_release,</span> <span class="pre">vm_vendor)</span></code> and <em>osinfo</em> being a tuple
  343. <code class="docutils literal notranslate"><span class="pre">(os_name,</span> <span class="pre">os_version,</span> <span class="pre">os_arch)</span></code>. Values which cannot be determined are set to
  344. the defaults given as parameters (which all default to <code class="docutils literal notranslate"><span class="pre">''</span></code>).</p>
  345. </dd></dl>
  346. </section>
  347. <section id="windows-platform">
  348. <h2>Windows Platform<a class="headerlink" href="#windows-platform" title="Link to this heading">¶</a></h2>
  349. <dl class="py function">
  350. <dt class="sig sig-object py" id="platform.win32_ver">
  351. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">win32_ver</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">release</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">version</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">csd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ptype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#platform.win32_ver" title="Link to this definition">¶</a></dt>
  352. <dd><p>Get additional version information from the Windows Registry and return a tuple
  353. <code class="docutils literal notranslate"><span class="pre">(release,</span> <span class="pre">version,</span> <span class="pre">csd,</span> <span class="pre">ptype)</span></code> referring to OS release, version number,
  354. CSD level (service pack) and OS type (multi/single processor). Values which
  355. cannot be determined are set to the defaults given as parameters (which all
  356. default to an empty string).</p>
  357. <p>As a hint: <em>ptype</em> is <code class="docutils literal notranslate"><span class="pre">'Uniprocessor</span> <span class="pre">Free'</span></code> on single processor NT machines
  358. and <code class="docutils literal notranslate"><span class="pre">'Multiprocessor</span> <span class="pre">Free'</span></code> on multi processor machines. The <em>‘Free’</em> refers
  359. to the OS version being free of debugging code. It could also state <em>‘Checked’</em>
  360. which means the OS version uses debugging code, i.e. code that checks arguments,
  361. ranges, etc.</p>
  362. </dd></dl>
  363. <dl class="py function">
  364. <dt class="sig sig-object py" id="platform.win32_edition">
  365. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">win32_edition</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.win32_edition" title="Link to this definition">¶</a></dt>
  366. <dd><p>Returns a string representing the current Windows edition, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the
  367. value cannot be determined. Possible values include but are not limited to
  368. <code class="docutils literal notranslate"><span class="pre">'Enterprise'</span></code>, <code class="docutils literal notranslate"><span class="pre">'IoTUAP'</span></code>, <code class="docutils literal notranslate"><span class="pre">'ServerStandard'</span></code>, and <code class="docutils literal notranslate"><span class="pre">'nanoserver'</span></code>.</p>
  369. <div class="versionadded">
  370. <p><span class="versionmodified added">New in version 3.8.</span></p>
  371. </div>
  372. </dd></dl>
  373. <dl class="py function">
  374. <dt class="sig sig-object py" id="platform.win32_is_iot">
  375. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">win32_is_iot</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.win32_is_iot" title="Link to this definition">¶</a></dt>
  376. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the Windows edition returned by <a class="reference internal" href="#platform.win32_edition" title="platform.win32_edition"><code class="xref py py-func docutils literal notranslate"><span class="pre">win32_edition()</span></code></a>
  377. is recognized as an IoT edition.</p>
  378. <div class="versionadded">
  379. <p><span class="versionmodified added">New in version 3.8.</span></p>
  380. </div>
  381. </dd></dl>
  382. </section>
  383. <section id="macos-platform">
  384. <h2>macOS Platform<a class="headerlink" href="#macos-platform" title="Link to this heading">¶</a></h2>
  385. <dl class="py function">
  386. <dt class="sig sig-object py" id="platform.mac_ver">
  387. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">mac_ver</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">release</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">versioninfo</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">('',</span> <span class="pre">'',</span> <span class="pre">'')</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">machine</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#platform.mac_ver" title="Link to this definition">¶</a></dt>
  388. <dd><p>Get macOS version information and return it as tuple <code class="docutils literal notranslate"><span class="pre">(release,</span> <span class="pre">versioninfo,</span>
  389. <span class="pre">machine)</span></code> with <em>versioninfo</em> being a tuple <code class="docutils literal notranslate"><span class="pre">(version,</span> <span class="pre">dev_stage,</span>
  390. <span class="pre">non_release_version)</span></code>.</p>
  391. <p>Entries which cannot be determined are set to <code class="docutils literal notranslate"><span class="pre">''</span></code>. All tuple entries are
  392. strings.</p>
  393. </dd></dl>
  394. </section>
  395. <section id="unix-platforms">
  396. <h2>Unix Platforms<a class="headerlink" href="#unix-platforms" title="Link to this heading">¶</a></h2>
  397. <dl class="py function">
  398. <dt class="sig sig-object py" id="platform.libc_ver">
  399. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">libc_ver</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">executable</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">sys.executable</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lib</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">version</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">chunksize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">16384</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#platform.libc_ver" title="Link to this definition">¶</a></dt>
  400. <dd><p>Tries to determine the libc version against which the file executable (defaults
  401. to the Python interpreter) is linked. Returns a tuple of strings <code class="docutils literal notranslate"><span class="pre">(lib,</span>
  402. <span class="pre">version)</span></code> which default to the given parameters in case the lookup fails.</p>
  403. <p>Note that this function has intimate knowledge of how different libc versions
  404. add symbols to the executable is probably only usable for executables compiled
  405. using <strong class="program">gcc</strong>.</p>
  406. <p>The file is read and scanned in chunks of <em>chunksize</em> bytes.</p>
  407. </dd></dl>
  408. </section>
  409. <section id="linux-platforms">
  410. <h2>Linux Platforms<a class="headerlink" href="#linux-platforms" title="Link to this heading">¶</a></h2>
  411. <dl class="py function">
  412. <dt class="sig sig-object py" id="platform.freedesktop_os_release">
  413. <span class="sig-prename descclassname"><span class="pre">platform.</span></span><span class="sig-name descname"><span class="pre">freedesktop_os_release</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#platform.freedesktop_os_release" title="Link to this definition">¶</a></dt>
  414. <dd><p>Get operating system identification from <code class="docutils literal notranslate"><span class="pre">os-release</span></code> file and return
  415. it as a dict. The <code class="docutils literal notranslate"><span class="pre">os-release</span></code> file is a <a class="reference external" href="https://www.freedesktop.org/software/systemd/man/os-release.html">freedesktop.org standard</a> and
  416. is available in most Linux distributions. A noticeable exception is
  417. Android and Android-based distributions.</p>
  418. <p>Raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> or subclass when neither <code class="docutils literal notranslate"><span class="pre">/etc/os-release</span></code> nor
  419. <code class="docutils literal notranslate"><span class="pre">/usr/lib/os-release</span></code> can be read.</p>
  420. <p>On success, the function returns a dictionary where keys and values are
  421. strings. Values have their special characters like <code class="docutils literal notranslate"><span class="pre">&quot;</span></code> and <code class="docutils literal notranslate"><span class="pre">$</span></code>
  422. unquoted. The fields <code class="docutils literal notranslate"><span class="pre">NAME</span></code>, <code class="docutils literal notranslate"><span class="pre">ID</span></code>, and <code class="docutils literal notranslate"><span class="pre">PRETTY_NAME</span></code> are always
  423. defined according to the standard. All other fields are optional. Vendors
  424. may include additional fields.</p>
  425. <p>Note that fields like <code class="docutils literal notranslate"><span class="pre">NAME</span></code>, <code class="docutils literal notranslate"><span class="pre">VERSION</span></code>, and <code class="docutils literal notranslate"><span class="pre">VARIANT</span></code> are strings
  426. suitable for presentation to users. Programs should use fields like
  427. <code class="docutils literal notranslate"><span class="pre">ID</span></code>, <code class="docutils literal notranslate"><span class="pre">ID_LIKE</span></code>, <code class="docutils literal notranslate"><span class="pre">VERSION_ID</span></code>, or <code class="docutils literal notranslate"><span class="pre">VARIANT_ID</span></code> to identify
  428. Linux distributions.</p>
  429. <p>Example:</p>
  430. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">get_like_distro</span><span class="p">():</span>
  431. <span class="n">info</span> <span class="o">=</span> <span class="n">platform</span><span class="o">.</span><span class="n">freedesktop_os_release</span><span class="p">()</span>
  432. <span class="n">ids</span> <span class="o">=</span> <span class="p">[</span><span class="n">info</span><span class="p">[</span><span class="s2">&quot;ID&quot;</span><span class="p">]]</span>
  433. <span class="k">if</span> <span class="s2">&quot;ID_LIKE&quot;</span> <span class="ow">in</span> <span class="n">info</span><span class="p">:</span>
  434. <span class="c1"># ids are space separated and ordered by precedence</span>
  435. <span class="n">ids</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">info</span><span class="p">[</span><span class="s2">&quot;ID_LIKE&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
  436. <span class="k">return</span> <span class="n">ids</span>
  437. </pre></div>
  438. </div>
  439. <div class="versionadded">
  440. <p><span class="versionmodified added">New in version 3.10.</span></p>
  441. </div>
  442. </dd></dl>
  443. </section>
  444. </section>
  445. <div class="clearer"></div>
  446. </div>
  447. </div>
  448. </div>
  449. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  450. <div class="sphinxsidebarwrapper">
  451. <div>
  452. <h3><a href="../contents.html">Table of Contents</a></h3>
  453. <ul>
  454. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code> — Access to underlying platform’s identifying data</a><ul>
  455. <li><a class="reference internal" href="#cross-platform">Cross Platform</a></li>
  456. <li><a class="reference internal" href="#java-platform">Java Platform</a></li>
  457. <li><a class="reference internal" href="#windows-platform">Windows Platform</a></li>
  458. <li><a class="reference internal" href="#macos-platform">macOS Platform</a></li>
  459. <li><a class="reference internal" href="#unix-platforms">Unix Platforms</a></li>
  460. <li><a class="reference internal" href="#linux-platforms">Linux Platforms</a></li>
  461. </ul>
  462. </li>
  463. </ul>
  464. </div>
  465. <div>
  466. <h4>Previous topic</h4>
  467. <p class="topless"><a href="curses.panel.html"
  468. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses.panel</span></code> — A panel stack extension for curses</a></p>
  469. </div>
  470. <div>
  471. <h4>Next topic</h4>
  472. <p class="topless"><a href="errno.html"
  473. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">errno</span></code> — Standard errno system symbols</a></p>
  474. </div>
  475. <div role="note" aria-label="source link">
  476. <h3>This Page</h3>
  477. <ul class="this-page-menu">
  478. <li><a href="../bugs.html">Report a Bug</a></li>
  479. <li>
  480. <a href="https://github.com/python/cpython/blob/main/Doc/library/platform.rst"
  481. rel="nofollow">Show Source
  482. </a>
  483. </li>
  484. </ul>
  485. </div>
  486. </div>
  487. <div id="sidebarbutton" title="Collapse sidebar">
  488. <span>«</span>
  489. </div>
  490. </div>
  491. <div class="clearer"></div>
  492. </div>
  493. <div class="related" role="navigation" aria-label="related navigation">
  494. <h3>Navigation</h3>
  495. <ul>
  496. <li class="right" style="margin-right: 10px">
  497. <a href="../genindex.html" title="General Index"
  498. >index</a></li>
  499. <li class="right" >
  500. <a href="../py-modindex.html" title="Python Module Index"
  501. >modules</a> |</li>
  502. <li class="right" >
  503. <a href="errno.html" title="errno — Standard errno system symbols"
  504. >next</a> |</li>
  505. <li class="right" >
  506. <a href="curses.panel.html" title="curses.panel — A panel stack extension for curses"
  507. >previous</a> |</li>
  508. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  509. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  510. <li class="switchers">
  511. <div class="language_switcher_placeholder"></div>
  512. <div class="version_switcher_placeholder"></div>
  513. </li>
  514. <li>
  515. </li>
  516. <li id="cpython-language-and-version">
  517. <a href="../index.html">3.12.3 Documentation</a> &#187;
  518. </li>
  519. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  520. <li class="nav-item nav-item-2"><a href="allos.html" >Generic Operating System Services</a> &#187;</li>
  521. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code> — Access to underlying platform’s identifying data</a></li>
  522. <li class="right">
  523. <div class="inline-search" role="search">
  524. <form class="inline-search" action="../search.html" method="get">
  525. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  526. <input type="submit" value="Go" />
  527. </form>
  528. </div>
  529. |
  530. </li>
  531. <li class="right">
  532. <label class="theme-selector-label">
  533. Theme
  534. <select class="theme-selector" oninput="activateTheme(this.value)">
  535. <option value="auto" selected>Auto</option>
  536. <option value="light">Light</option>
  537. <option value="dark">Dark</option>
  538. </select>
  539. </label> |</li>
  540. </ul>
  541. </div>
  542. <div class="footer">
  543. &copy;
  544. <a href="../copyright.html">
  545. Copyright
  546. </a>
  547. 2001-2024, Python Software Foundation.
  548. <br />
  549. This page is licensed under the Python Software Foundation License Version 2.
  550. <br />
  551. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  552. <br />
  553. See <a href="/license.html">History and License</a> for more information.<br />
  554. <br />
  555. The Python Software Foundation is a non-profit corporation.
  556. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  557. <br />
  558. <br />
  559. Last updated on Apr 09, 2024 (13:47 UTC).
  560. <a href="/bugs.html">Found a bug</a>?
  561. <br />
  562. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  563. </div>
  564. </body>
  565. </html>
上海开阖软件有限公司 沪ICP备12045867号-1