{"id":167989,"date":"2022-04-23T05:46:19","date_gmt":"2022-04-22T21:46:19","guid":{"rendered":"http:\/\/www.idc.net\/help\/167989\/"},"modified":"2022-04-23T05:46:19","modified_gmt":"2022-04-22T21:46:19","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9a1-%e5%91%bd%e4%bb%a4%e8%a1%8c%e4%b8%8e%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/167989\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1a1. \u547d\u4ee4\u884c\u4e0e\u73af\u5883"},"content":{"rendered":"<h1>1. \u547d\u4ee4\u884c\u4e0e\u73af\u5883<\/h1>\n<p>\u4e3a\u83b7\u53d6\u5404\u79cd\u8bbe\u7f6e\u4fe1\u606f\uff0cCPython \u89e3\u6790\u5668\u4f1a\u626b\u63cf\u547d\u4ee4\u884c\u4e0e\u73af\u5883\u3002<\/p>\n<p><strong>CPython \u5b9e\u73b0\u7ec6\u8282\uff1a<\/strong> \u5176\u4ed6\u5b9e\u73b0\u7684\u547d\u4ee4\u884c\u65b9\u6848\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002 \u8be6\u89c1 \u5176\u4ed6\u5b9e\u73b0\u3002<\/p>\n<h2>1.1. \u547d\u4ee4\u884c<\/h2>\n<p>\u8c03\u7528 Python \u65f6\uff0c\u53ef\u4ee5\u6307\u5b9a\u4e0b\u5217\u4efb\u610f\u9009\u9879\uff1a<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><code><span>python <\/span><span>[-<\/span><span>bBdEhiIOqsSuvVWx<\/span><span>?]<\/span><span> <\/span><span>[-<\/span><span>c command <\/span><span>|<\/span><span> <\/span><span>-<\/span><span>m <\/span><span>module<\/span><span>-<\/span><span>name <\/span><span>|<\/span><span> script <\/span><span>|<\/span><span> <\/span><span>-<\/span><span> <\/span><span>]<\/span><span> <\/span><span>[<\/span><span>args<\/span><span>]<\/span><\/code><\/li>\n \n \n \n <\/ol><\/pre>\n<p>\u6700\u5e38\u89c1\u7684\u7528\u4f8b\u662f\u542f\u52a8\u65f6\u6267\u884c\u811a\u672c\uff1a<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><code><span>python myscript<\/span><span>.<\/span><span>py<\/span><\/code><\/li>\n \n \n \n <\/ol><\/pre>\n<h3>1.1.1. \u63a5\u53e3\u9009\u9879<\/h3>\n<p>\u89e3\u91ca\u5668\u63a5\u53e3\u7c7b\u4f3c\u4e8e UNIX shell\uff0c\u4f46\u63d0\u4f9b\u4e86\u989d\u5916\u7684\u8c03\u7528\u65b9\u6cd5:<\/p>\n<ul>\n<li>\n<p>\u7528\u8fde\u63a5\u5230 tty \u8bbe\u5907\u7684\u6807\u51c6\u8f93\u5165\u8c03\u7528\u65f6\uff0c\u4f1a\u63d0\u793a\u8f93\u5165\u5e76\u6267\u884c\u547d\u4ee4\uff0c\u8f93\u5165 EOF \uff08\u6587\u4ef6\u7ed3\u675f\u7b26\uff0cUNIX \u4e2d\u6309 Ctrl-D\uff0cWindows \u4e2d\u6309 Ctrl-Z, Enter\uff09\u65f6\u7ec8\u6b62\u3002<\/p>\n<\/li>\n<li>\n<p>\u7528\u6587\u4ef6\u540d\u53c2\u6570\u6216\u4ee5\u6807\u51c6\u8f93\u5165\u6587\u4ef6\u8c03\u7528\u65f6\uff0c\u8bfb\u53d6\uff0c\u5e76\u6267\u884c\u8be5\u811a\u672c\u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>\u7528\u76ee\u5f55\u540d\u53c2\u6570\u8c03\u7528\u65f6\uff0c\u4ece\u8be5\u76ee\u5f55\u8bfb\u53d6\u3001\u6267\u884c\u9002\u5f53\u540d\u79f0\u7684\u811a\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>\u7528 <code>-c command<\/code> \u8c03\u7528\u65f6\uff0c\u6267\u884c <em>command<\/em> \u8868\u793a\u7684 Python \u8bed\u53e5\u3002<em>command<\/em> \u53ef\u4ee5\u5305\u542b\u7528\u6362\u884c\u7b26\u5206\u9694\u7684\u591a\u6761\u8bed\u53e5\u3002\u6ce8\u610f\uff0c\u524d\u5bfc\u7a7a\u767d\u5b57\u7b26\u5728 Python \u8bed\u53e5\u4e2d\u975e\u5e38\u91cd\u8981\uff01<\/p>\n<\/li>\n<li>\n<p>\u7528 <code>-m module-name<\/code> \u8c03\u7528\u65f6\uff0c\u5728 Python \u6a21\u5757\u8def\u5f84\u4e2d\u67e5\u627e\u6307\u5b9a\u7684\u6a21\u5757\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u811a\u672c\u6267\u884c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u975e\u4ea4\u4e92\u6a21\u5f0f\u4e0b\uff0c\u5148\u89e3\u6790\u5168\u90e8\u8f93\u5165\uff0c\u518d\u6267\u884c\u3002<\/p>\n<p>\u63a5\u53e3\u9009\u9879\u4f1a\u7ec8\u7ed3\u89e3\u91ca\u5668\u8bfb\u5165\u7684\u9009\u9879\u5217\u8868\uff0c\u6240\u6709\u540e\u7eed\u53c2\u6570\u90fd\u5728 sys.argv \u91cc \u2014 \u6ce8\u610f\uff0c\u9996\u4e2a\u5143\u7d20\uff0c\u5373\u4e0b\u6807\u4e3a\u96f6\u7684\u5143\u7d20\uff08<code>sys.argv[0]<\/code>\uff09\u662f\u8868\u793a\u7a0b\u5e8f\u6765\u6e90\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>-c &lt;command&gt;<\/p>\n<p>\u6267\u884c <em>command<\/em> \u4e2d\u7684 Python \u4ee3\u7801\u3002<em>command<\/em> \u53ef\u4ee5\u662f\u4e00\u6761\u8bed\u53e5\uff0c\u4e5f\u53ef\u4ee5\u662f\u7528\u6362\u884c\u7b26\u5206\u9694\u7684\u591a\u6761\u8bed\u53e5\uff0c\u5176\u4e2d\uff0c\u524d\u5bfc\u7a7a\u767d\u5b57\u7b26\u4e0e\u666e\u901a\u6a21\u5757\u4ee3\u7801\u4e2d\u7684\u4f5c\u7528\u4e00\u6837\u3002<\/p>\n<p>\u4f7f\u7528\u6b64\u9009\u9879\u65f6\uff0csys.argv \u7684\u9996\u4e2a\u5143\u7d20\u4e3a <code>\"-c\"<\/code>\uff0c\u5e76\u4f1a\u628a\u5f53\u524d\u76ee\u5f55\u52a0\u5165\u81f3 sys.path \u5f00\u5934\uff08\u8ba9\u8be5\u76ee\u5f55\u4e2d\u7684\u6a21\u5757\u4f5c\u4e3a\u9876\u5c42\u6a21\u5757\u5bfc\u5165\uff09\u3002<\/p>\n<p>\u4f7f\u7528 <code>command<\/code> \u53c2\u6570\u4f1a\u5f15\u53d1 \u5ba1\u8ba1\u4e8b\u4ef6 <code>cpython.run_command<\/code> \u3002<\/p>\n<p>-m &lt;module-name&gt;<\/p>\n<p>\u5728 sys.path \u4e2d\u641c\u7d22\u6307\u5b9a\u6a21\u5757\uff0c\u5e76\u4ee5 __main__ \u6a21\u5757\u6267\u884c\u5176\u5185\u5bb9\u3002<\/p>\n<p>\u8be5\u53c2\u6570\u662f <em>\u6a21\u5757\u540d<\/em>\uff0c\u8bf7\u52ff\u8f93\u5165\u6587\u4ef6\u6269\u5c55\u540d\uff08<code>.py<\/code>\uff09\u3002\u6a21\u5757\u540d\u5e94\u4e3a\u6709\u6548\u7684\u7edd\u5bf9 Python \u6a21\u5757\u540d\uff0c\u4f46\u672c\u5b9e\u73b0\u5bf9\u6b64\u4e0d\u4f5c\u5f3a\u5236\u8981\u6c42\uff08\u4f8b\u5982\uff0c\u5141\u8bb8\u4f7f\u7528\u542b\u8fde\u5b57\u7b26 <code>-<\/code> \u7684\u540d\u79f0\uff09\u3002<\/p>\n<p>\u5305\u540d\u79f0\uff08\u5305\u62ec\u547d\u540d\u7a7a\u95f4\u5305\uff09\u4e5f\u5141\u8bb8\u4f7f\u7528\u3002\u4f7f\u7528\u5305\u540d\u79f0\u800c\u4e0d\u662f\u666e\u901a\u6a21\u5757\u540d\u65f6\uff0c\u89e3\u91ca\u5668\u628a <code>&lt;pkg&gt;.__main__<\/code> \u4f5c\u4e3a\u4e3b\u6a21\u5757\u6267\u884c\u3002\u6b64\u884c\u4e3a\u7279\u610f\u88ab\u8bbe\u8ba1\u4e3a\u4e0e\u4f5c\u4e3a\u811a\u672c\u53c2\u6570\u4f20\u9012\u7ed9\u89e3\u91ca\u5668\u7684\u76ee\u5f55\u548c zip \u6587\u4ef6\u7684\u5904\u7406\u65b9\u5f0f\u7c7b\u4f3c\u3002<\/p>\n<p>\u5907\u6ce8<\/p>\n<p>\u6b64\u9009\u9879\u4e0d\u9002\u7528\u4e8e\u5185\u7f6e\u6a21\u5757\u548c\u4ee5 C \u7f16\u5199\u7684\u6269\u5c55\u6a21\u5757\uff0c\u56e0\u4e3a\u5b83\u4eec\u5e76\u6ca1\u6709\u5bf9\u5e94\u7684 Python \u6a21\u5757\u6587\u4ef6\u3002 \u4f46\u662f\u5b83\u4ecd\u7136\u9002\u7528\u4e8e\u9884\u7f16\u8bd1\u7684\u6a21\u5757\uff0c\u5373\u4f7f\u6ca1\u6709\u53ef\u7528\u7684\u521d\u59cb\u6e90\u6587\u4ef6\u3002<\/p>\n<p>\u5982\u679c\u7ed9\u51fa\u6b64\u9009\u9879\uff0csys.argv \u7684\u9996\u4e2a\u5143\u7d20\u5c06\u4e3a\u6a21\u5757\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84 (\u5728\u5b9a\u4f4d\u6a21\u5757\u6587\u4ef6\u671f\u95f4\uff0c\u9996\u4e2a\u5143\u7d20\u5c06\u8bbe\u4e3a <code>\"-m\"<\/code>)\u3002 \u4e0e -c \u9009\u9879\u4e00\u6837\uff0c\u5f53\u524d\u76ee\u5f55\u5c06\u88ab\u52a0\u5165 sys.path \u7684\u5f00\u5934\u3002<\/p>\n<p>-I \u9009\u9879\u53ef\u7528\u6765\u5728\u9694\u79bb\u6a21\u5f0f\u4e0b\u8fd0\u884c\u811a\u672c\uff0c\u6b64\u6a21\u5f0f\u4e2d sys.path \u65e2\u4e0d\u5305\u542b\u5f53\u524d\u76ee\u5f55\u4e5f\u4e0d\u5305\u542b\u7528\u6237\u7684 site-packages \u76ee\u5f55\u3002 \u6240\u6709 <code>PYTHON*<\/code> \u73af\u5883\u53d8\u91cf\u4e5f\u4f1a\u88ab\u5ffd\u7565\u3002<\/p>\n<p>\u8bb8\u591a\u6807\u51c6\u5e93\u6a21\u5757\u90fd\u5305\u542b\u5728\u6267\u884c\u65f6\uff0c\u4ee5\u811a\u672c\u65b9\u5f0f\u8c03\u7528\u7684\u4ee3\u7801\u3002\u4f8b\u5982 timeit \u6a21\u5757\uff1a<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><code><span>python <\/span><span>-<\/span><span>m timeit <\/span><span>-<\/span><span>s <\/span><span>'setup here'<\/span><span> <\/span><span>'benchmarked code here'<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>python <\/span><span>-<\/span><span>m timeit <\/span><span>-<\/span><span>h <\/span><span># for details<\/span><\/code><\/li>\n \n \n \n <\/ol><\/pre>\n<p>\u4f7f\u7528 <code>module-name<\/code> \u53c2\u6570\u4f1a\u5f15\u53d1 \u5ba1\u8ba1\u4e8b\u4ef6 <code>cpython.run_module<\/code> \u3002<\/p>\n<p>\u53c2\u89c1<\/p>\n<ul>\n<li>\n<p>runpy.run_module()<\/p>\n<p>Python \u4ee3\u7801\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7684\u7b49\u6548\u529f\u80fd<\/p>\n<\/li>\n<\/ul>\n<p>PEP 338 \u2014 \u5c06\u6a21\u5757\u4f5c\u4e3a\u811a\u672c\u6267\u884c<\/p>\n<p>\u5728 3.1 \u7248\u66f4\u6539: \u63d0\u4f9b\u5305\u540d\u79f0\u6765\u8fd0\u884c <code>__main__<\/code> \u5b50\u6a21\u5757\u3002<\/p>\n<p>\u5728 3.4 \u7248\u66f4\u6539: \u540c\u6837\u652f\u6301\u547d\u540d\u7a7a\u95f4\u5305<\/p>\n<p>-<\/p>\n<p>\u4ece\u6807\u51c6\u8f93\u5165 (sys.stdin) \u8bfb\u53d6\u547d\u4ee4\u3002\u6807\u51c6\u8f93\u5165\u4e3a\u7ec8\u7aef\u65f6\uff0c\u4f7f\u7528 -i\u3002<\/p>\n<p>\u4f7f\u7528\u6b64\u9009\u9879\u65f6\uff0csys.argv \u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u662f <code>\"-\"<\/code>\uff0c \u540c\u65f6\uff0c\u628a\u5f53\u524d\u76ee\u5f55\u52a0\u5165 sys.path \u5f00\u5934\u3002<\/p>\n<p>\u6ca1\u6709\u53c2\u6570\u65f6\uff0c\u4f1a\u89e6\u53d1 \u5ba1\u8ba1\u4e8b\u4ef6 <code>cpython.run_stdin<\/code> \u3002<\/p>\n<p>&lt;script&gt;<\/p>\n<p>\u6267\u884c <em>script<\/em> \u4e2d\u7684 Python \u4ee3\u7801\uff0c\u8be5\u53c2\u6570\u5e94\u4e3a\uff08\u7edd\u5bf9\u6216\u76f8\u5bf9\uff09\u6587\u4ef6\u7cfb\u7edf\u8def\u5f84\uff0c\u6307\u5411 Python \u6587\u4ef6\u3001\u5305\u542b <code>__main__.py<\/code> \u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u6216\u5305\u542b <code>__main__.py<\/code> \u6587\u4ef6\u7684 zip \u6587\u4ef6\u3002<\/p>\n<p>\u7ed9\u51fa\u6b64\u9009\u9879\u65f6\uff0csys.argv \u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u5c31\u662f\u5728\u547d\u4ee4\u884c\u4e2d\u6307\u5b9a\u7684\u811a\u672c\u540d\u79f0\u3002<\/p>\n<p>\u5982\u679c\u811a\u672c\u540d\u79f0\u76f4\u63a5\u6307\u5411 Python \u6587\u4ef6\uff0c\u5219\u628a\u8be5\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u52a0\u5165 sys.path \u7684\u5f00\u5934\uff0c\u5e76\u4e14\u628a\u8be5\u6587\u4ef6\u5f53\u4f5c __main__ \u6a21\u5757\u6765\u6267\u884c\u3002<\/p>\n<p>\u5982\u679c\u811a\u672c\u540d\u79f0\u6307\u5411\u76ee\u5f55\u6216 zip \u6587\u4ef6\uff0c\u5219\u628a\u811a\u672c\u540d\u52a0\u5165 sys.path \u7684\u5f00\u5934\uff0c\u5e76\u628a\u8be5\u4f4d\u7f6e\u4e2d\u7684 <code>__main__.py<\/code> \u6587\u4ef6\u5f53\u4f5c __main__ \u6a21\u5757\u6765\u6267\u884c\u3002<\/p>\n<p>-I \u9009\u9879\u4ee5\u9694\u79bb\u6a21\u5f0f\u8fd0\u884c\u811a\u672c\uff0c\u6b64\u6a21\u5f0f\u4e2d\uff0csys.path \u65e2\u4e0d\u5305\u542b\u811a\u672c\u76ee\u5f55\uff0c\u4e5f\u4e0d\u5305\u542b\u7528\u6237\u7684 site-packages \u76ee\u5f55\uff0c\u8fd8\u4f1a\u5ffd\u7565\u6240\u6709 <code>PYTHON*<\/code> \u73af\u5883\u53d8\u91cf\u3002<\/p>\n<p>\u4f7f\u7528 <code>filename<\/code> \u53c2\u6570\u4f1a\u5f15\u53d1 \u5ba1\u8ba1\u4e8b\u4ef6 <code>cpython.run_file<\/code> \u3002<\/p>\n<p>\u53c2\u89c1<\/p>\n<ul>\n<li>\n<p>runpy.run_path()<\/p>\n<p>Python \u4ee3\u7801\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7684\u7b49\u6548\u529f\u80fd<\/p>\n<\/li>\n<\/ul>\n<p>\u672a\u7ed9\u51fa\u63a5\u53e3\u9009\u9879\u65f6\uff0c\u4f7f\u7528 -i\uff0c<code>sys.argv[0]<\/code> \u4e3a\u7a7a\u5b57\u7b26\u4e32 (<code>\"\"<\/code>)\uff0c\u5e76\u628a\u5f53\u524d\u76ee\u5f55\u52a0\u81f3 sys.path \u7684\u5f00\u5934\u3002 \u6b64\u5916\uff0c\u5982\u679c\u7cfb\u7edf\u652f\u6301\uff0c\u8fd8\u80fd\u81ea\u52a8\u542f\u7528 tab \u8865\u5168\u548c\u5386\u53f2\u7f16\u8f91\uff08\u53c2\u89c1 Readline \u914d\u7f6e\uff09\u3002<\/p>\n<p>\u53c2\u89c1<\/p>\n<p>\u8c03\u7528\u89e3\u91ca\u5668<\/p>\n<p>\u5728 3.4 \u7248\u66f4\u6539: \u81ea\u52a8\u542f\u7528 tab \u8865\u5168\u548c\u5386\u53f2\u7f16\u8f91\u3002<\/p>\n<h3>1.1.2. \u901a\u7528\u9009\u9879<\/h3>\n<p>-?<\/p>\n<p>-h<\/p>\n<p>--help<\/p>\n<p>Print a short description of all command line options and corresponding environment variables and exit.<\/p>\n<p>--help-env<\/p>\n<p>Print a short description of Python-specific environment variables and exit.<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>--help-xoptions<\/p>\n<p>Print a description of implementation-specific -X options and exit.<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>--help-all<\/p>\n<p>Print complete usage information and exit.<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>-V<\/p>\n<p>--version<\/p>\n<p>\u8f93\u51fa Python \u7248\u672c\u53f7\u5e76\u9000\u51fa\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><code><span>Python<\/span><span> <\/span><span>3.8<\/span><span>.<\/span><span>0b2<\/span><span>+<\/span><\/code><\/li>\n \n \n \n <\/ol><\/pre>\n<p>\u8f93\u5165\u4e24\u6b21 <code>V<\/code> \u9009\u9879\u65f6\uff0c\u8f93\u51fa\u66f4\u591a\u6784\u5efa\u4fe1\u606f\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><code><span>Python<\/span><span> <\/span><span>3.8<\/span><span>.<\/span><span>0b2<\/span><span>+<\/span><span> <\/span><span>(<\/span><span>3.8<\/span><span>:<\/span><span>0c076caaa8<\/span><span>,<\/span><span> <\/span><span>Apr<\/span><span> <\/span><span>20<\/span><span> <\/span><span>2019<\/span><span>,<\/span><span> <\/span><span>21<\/span><span>:<\/span><span>55<\/span><span>:<\/span><span>00<\/span><span>)<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>[<\/span><span>GCC <\/span><span>6.2<\/span><span>.<\/span><span>0<\/span><span> <\/span><span>20161005<\/span><span>]<\/span><\/code><\/li>\n \n \n \n <\/ol><\/pre>\n<p>3.6 \u65b0\u7248\u529f\u80fd: <code>-VV<\/code> \u9009\u9879\u3002<\/p>\n<h3>1.1.3. \u5176\u4ed6\u9009\u9879<\/h3>\n<p>-b<\/p>\n<p>\u7528 str \u4e0e bytes \u6216 bytearray \u5bf9\u6bd4\uff0c \u6216\u5bf9\u6bd4 bytes \u4e0e int \u65f6\uff0c\u4f1a\u53d1\u51fa\u8b66\u544a\u3002\u91cd\u590d\u7ed9\u51fa\u8be5\u9009\u9879\uff08<code>-bb<\/code>\uff09\u65f6\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u5728 3.5 \u7248\u66f4\u6539: \u5f71\u54cd bytes \u4e0e int \u7684\u6bd4\u8f83\u3002<\/p>\n<p>-B<\/p>\n<p>\u7ed9\u51fa\u6b64\u9009\u9879\u65f6\uff0cPython \u4e0d\u5728\u5bfc\u5165\u6e90\u6a21\u5757\u65f6\u5199\u5165 <code>.pyc<\/code> \u6587\u4ef6\u3002\u53e6\u8bf7\u53c2\u9605 PYTHONDONTWRITEBYTECODE\u3002<\/p>\n<p>--check-hash-based-pycs default|always|never<\/p>\n<p>\u63a7\u5236\u57fa\u4e8e\u54c8\u5e0c\u503c\u7684 <code>.pyc<\/code> \u6587\u4ef6\u7684\u9a8c\u8bc1\u884c\u4e3a\u3002 \u53c2\u89c1 \u5df2\u7f13\u5b58\u5b57\u8282\u7801\u7684\u5931\u6548\u3002 \u5f53\u8bbe\u4e3a <code>default<\/code> \u65f6\uff0c\u5df2\u9009\u5b9a\u548c\u672a\u9009\u5b9a\u7684\u57fa\u4e8e\u54c8\u5e0c\u503c\u7684\u5b57\u8282\u7801\u7f13\u5b58\u6587\u4ef6\u5c06\u6839\u636e\u5176\u9ed8\u8ba4\u8bed\u4e49\u8fdb\u884c\u9a8c\u8bc1\u3002 \u5f53\u8bbe\u4e3a <code>always<\/code> \u65f6\uff0c\u6240\u6709\u57fa\u4e8e\u54c8\u5e0c\u503c\u7684 <code>.pyc<\/code> \u6587\u4ef6\uff0c\u4e0d\u8bba\u662f\u5df2\u9009\u5b9a\u8fd8\u662f\u672a\u9009\u5b9a\u7684\u90fd\u5c06\u6839\u636e\u5176\u5bf9\u5e94\u7684\u6e90\u6587\u4ef6\u8fdb\u884c\u9a8c\u8bc1\u3002 \u5f53\u8bbe\u4e3a <code>never<\/code> \u65f6\uff0c\u57fa\u4e8e\u54c8\u5e0c\u503c\u7684 <code>.pyc<\/code> \u6587\u4ef6\u5c06\u4e0d\u4f1a\u6839\u636e\u5176\u5bf9\u5e94\u7684\u6e90\u6587\u4ef6\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n<p>\u57fa\u4e8e\u65f6\u95f4\u6233\u7684 <code>.pyc<\/code> \u6587\u4ef6\u7684\u8bed\u4e49\u4e0d\u4f1a\u53d7\u6b64\u9009\u9879\u5f71\u54cd\u3002<\/p>\n<p>-d<\/p>\n<p>\u5f00\u542f\u89e3\u6790\u5668\u8c03\u8bd5\u8f93\u51fa\uff08\u9650\u4e13\u5bb6\u4f7f\u7528\uff0c\u4f9d\u8d56\u4e8e\u7f16\u8bd1\u9009\u9879\uff09\u3002 \u53e6\u8bf7\u53c2\u9605 PYTHONDEBUG\u3002<\/p>\n<p>-E<\/p>\n<p>\u5ffd\u7565\u6240\u6709 <code>PYTHON*<\/code> \u73af\u5883\u53d8\u91cf\uff0c\u4f8b\u5982\uff0c\u5df2\u8bbe\u7f6e\u7684 PYTHONPATH \u548c PYTHONHOME\u3002<\/p>\n<p>See also the -P and -I (isolated) options.<\/p>\n<p>-i<\/p>\n<p>\u811a\u672c\u662f\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u6216\u4f7f\u7528 -c \u65f6\uff0c\u5373\u4fbf sys.stdin \u4e0d\u662f\u7ec8\u7aef\uff0c\u6267\u884c\u811a\u672c\u6216\u547d\u4ee4\u540e\uff0c\u4e5f\u4f1a\u8fdb\u5165\u4ea4\u4e92\u6a21\u5f0f\u3002\u4e0d\u8bfb\u53d6 PYTHONSTARTUP \u6587\u4ef6\u3002<\/p>\n<p>\u672c\u9009\u9879\u7528\u4e8e\uff0c\u811a\u672c\u89e6\u53d1\u5f02\u5e38\u65f6\uff0c\u68c0\u67e5\u5168\u5c40\u53d8\u91cf\u6216\u5806\u6808\u56de\u6eaf\u3002 \u8be6\u89c1 PYTHONINSPECT\u3002<\/p>\n<p>-I<\/p>\n<p>Run Python in isolated mode. This also implies -E, -P and -s options.<\/p>\n<p>In isolated mode sys.path contains neither the script\u2019s directory nor the user\u2019s site-packages directory. All <code>PYTHON*<\/code> environment variables are ignored, too. Further restrictions may be imposed to prevent the user from injecting malicious code.<\/p>\n<p>3.4 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>-O<\/p>\n<p>\u79fb\u9664 assert \u8bed\u53e5\u4ee5\u53ca\u4efb\u4f55\u4ee5 __debug__ \u7684\u503c\u4f5c\u4e3a\u6761\u4ef6\u7684\u4ee3\u7801\u3002 \u901a\u8fc7\u5728 <code>.pyc<\/code> \u6269\u5c55\u540d\u4e4b\u524d\u6dfb\u52a0 <code>.opt-1<\/code> \u6765\u6269\u5145\u5df2\u7f16\u8bd1\u6587\u4ef6 (bytecode) \u7684\u6587\u4ef6\u540d (\u53c2\u89c1 PEP 488)\u3002 \u53e6\u8bf7\u53c2\u9605 PYTHONOPTIMIZE\u3002<\/p>\n<p>\u5728 3.5 \u7248\u66f4\u6539: \u4f9d\u636e PEP 488 \u4fee\u6539 <code>.pyc<\/code> \u6587\u4ef6\u540d\u3002<\/p>\n<p>-OO<\/p>\n<p>\u5728\u542f\u7528 -O \u7684\u540c\u65f6\u4e22\u5f03\u6587\u6863\u5b57\u7b26\u4e32\u3002 \u901a\u8fc7\u5728 <code>.pyc<\/code> \u6269\u5c55\u540d\u4e4b\u524d\u6dfb\u52a0 <code>.opt-2<\/code> \u6765\u6269\u5c55\u5df2\u7f16\u8bd1\u6587\u4ef6 (bytecode) \u7684\u6587\u4ef6\u540d (\u53c2\u89c1 PEP 488)\u3002<\/p>\n<p>\u5728 3.5 \u7248\u66f4\u6539: \u4f9d\u636e PEP 488 \u4fee\u6539 <code>.pyc<\/code> \u6587\u4ef6\u540d\u3002<\/p>\n<p>-P<\/p>\n<p>Don\u2019t prepend a potentially unsafe path to sys.path:<\/p>\n<ul>\n<li>\n<p><code>python -m module<\/code> command line: Don\u2019t prepend the current working directory.<\/p>\n<\/li>\n<li>\n<p><code>python script.py<\/code> command line: Don\u2019t prepend the script\u2019s directory. If it\u2019s a symbolic link, resolve symbolic links.<\/p>\n<\/li>\n<li>\n<p><code>python -c code<\/code> and <code>python<\/code> (REPL) command lines: Don\u2019t prepend an empty string, which means the current working directory.<\/p>\n<\/li>\n<\/ul>\n<p>See also the PYTHONSAFEPATH environment variable, and -E and -I (isolated) options.<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>-q<\/p>\n<p>\u5373\u4f7f\u5728\u4ea4\u4e92\u6a21\u5f0f\u4e0b\u4e5f\u4e0d\u663e\u793a\u7248\u6743\u548c\u7248\u672c\u4fe1\u606f\u3002<\/p>\n<p>3.2 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>-R<\/p>\n<p>\u5f00\u542f\u54c8\u5e0c\u968f\u673a\u5316\u3002 \u6b64\u9009\u9879\u6743 PYTHONHASHSEED \u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u4e3a <code>0<\/code> \u65f6\u8d77\u4f5c\u7528\uff0c\u56e0\u4e3a\u54c8\u5e0c\u968f\u673a\u5316\u662f\u9ed8\u8ba4\u542f\u7528\u7684\u3002<\/p>\n<p>\u5728Python\u7684\u65e9\u671f\u7248\u672c\u4e2d\uff0c\u6b64\u9009\u9879\u542f\u7528\u54c8\u5e0c\u968f\u673a\u5316\uff0c\u5c06 str \u548c bytes \u7684\u5bf9\u8c61 <code>__hash__()<\/code> \u7684\u503c \u201c\u52a0\u76d0\u201d \u4e3a\u4e0d\u53ef\u9884\u6d4b\u7684\u968f\u673a\u503c\u3002\u867d\u7136\u5b83\u4eec\u5728\u5355\u4e2aPython\u8fdb\u7a0b\u4e2d\u4fdd\u6301\u4e0d\u53d8\uff0c\u4f46\u662f\u5728\u91cd\u590d\u8c03\u7528\u7684Python\u8fdb\u7a0b\u4e4b\u95f4\u5b83\u4eec\u662f\u4e0d\u53ef\u9884\u6d4b\u7684\u3002<\/p>\n<p>Hash randomization is intended to provide protection against a denial-of-service caused by carefully chosen inputs that exploit the worst case performance of a dict construction, O(n2) complexity. See http:\/\/www.ocert.org\/advisories\/ocert-2011-003.html for details.<\/p>\n<p>PYTHONHASHSEED \u5141\u8bb8\u4f60\u4e3a\u54c8\u5e0c\u79cd\u5b50\u5bc6\u7801\u8bbe\u7f6e\u4e00\u4e2a\u56fa\u5b9a\u503c\u3002<\/p>\n<p>\u5728 3.7 \u7248\u66f4\u6539: \u6b64\u9009\u9879\u4e0d\u4f1a\u518d\u88ab\u5ffd\u7565\u3002<\/p>\n<p>3.2.3 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>-s<\/p>\n<p>\u4e0d\u8981\u5c06 \u7528\u6237 site-packages \u76ee\u5f55 \u6dfb\u52a0\u5230 sys.path\u3002<\/p>\n<p>\u53c2\u89c1<\/p>\n<p>PEP 370 \u2014 \u5206\u7528\u6237\u7684 site-packages \u76ee\u5f55<\/p>\n<p>-S<\/p>\n<p>\u7981\u7528 site \u7684\u5bfc\u5165\u53ca\u5176\u6240\u9644\u5e26\u7684\u57fa\u4e8e\u7ad9\u70b9\u5bf9 sys.path \u7684\u64cd\u4f5c\u3002 \u5982\u679c site \u4f1a\u5728\u7a0d\u540e\u88ab\u663e\u5f0f\u5730\u5bfc\u5165\u4e5f\u4f1a\u7981\u7528\u8fd9\u4e9b\u64cd\u4f5c (\u5982\u679c\u4f60\u5e0c\u671b\u89e6\u53d1\u5b83\u4eec\u5219\u5e94\u8c03\u7528 site.main())\u3002<\/p>\n<p>-u<\/p>\n<p>\u5f3a\u5236 stdout \u548c stderr \u6d41\u4e0d\u4f7f\u7528\u7f13\u51b2\u3002 \u6b64\u9009\u9879\u5bf9 stdin \u6d41\u65e0\u5f71\u54cd\u3002<\/p>\n<p>\u53e6\u8bf7\u53c2\u9605 PYTHONUNBUFFERED\u3002<\/p>\n<p>\u5728 3.7 \u7248\u66f4\u6539: stdout \u548c stderr \u6d41\u5728\u6587\u672c\u5c42\u73b0\u5728\u4e0d\u4f7f\u7528\u7f13\u51b2\u3002<\/p>\n<p>-v<\/p>\n<p>\u6bcf\u6b21\u5728\u521d\u59cb\u5316\u6a21\u5757\u65f6\u4f1a\u6253\u5370\u4e00\u6761\u4fe1\u606f\uff0c\u663e\u793a\u88ab\u52a0\u8f7d\u7684\u5730\u65b9\uff08\u6587\u4ef6\u540d\u6216\u5185\u7f6e\u6a21\u5757\u540d\uff09\u3002\u5f53\u7ed9\u51fa\u4e24\u4e2av\uff08 <code>-vv<\/code> \uff09\u65f6\uff0c\u641c\u7d22\u6a21\u5757\u65f6\u4f1a\u4e3a\u6bcf\u4e2a\u6587\u4ef6\u6253\u5370\u4e00\u6761\u4fe1\u606f\u3002\u9000\u51fa\u65f6\u6a21\u5757\u6e05\u7406\u7684\u4fe1\u606f\u4e5f\u4f1a\u7ed9\u51fa\u6765\u3002<\/p>\n<p>\u5728 3.10 \u7248\u66f4\u6539: \u7531 site \u6a21\u5757\u53ef\u4ee5\u5f97\u5230\u5c06\u8981\u5904\u7406\u7684\u7ad9\u70b9\u8def\u5f84\u548c <code>.pth<\/code> \u6587\u4ef6\u3002<\/p>\n<p>\u53c2\u9605 PYTHONVERBOSE \u3002<\/p>\n<p>-W arg<\/p>\n<p>\u8b66\u544a\u4fe1\u606f\u7684\u63a7\u5236\u3002Python \u7684\u8b66\u544a\u673a\u5236\u9ed8\u8ba4\u5c06\u8b66\u544a\u4fe1\u606f\u6253\u5370\u5230 sys.stderr\u3002<\/p>\n<p>\u6700\u7b80\u5355\u7684\u8bbe\u7f6e\u662f\u5c06\u67d0\u4e2a\u7279\u5b9a\u64cd\u4f5c\u65e0\u6761\u4ef6\u5730\u5e94\u7528\u4e8e\u8fdb\u7a0b\u6240\u53d1\u51fa\u6240\u6709\u8b66\u544a (\u5373\u4f7f\u662f\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u5ffd\u7565\u7684\u90a3\u4e9b\u8b66\u544a):<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><code><span>-<\/span><span>Wdefault<\/span><span> <\/span><span># Warn once per call location<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>-<\/span><span>Werror<\/span><span> <\/span><span># Convert to exceptions<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>-<\/span><span>Walways<\/span><span> <\/span><span># Warn every time<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>-<\/span><span>Wmodule<\/span><span> <\/span><span># Warn once per calling module<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>-<\/span><span>Wonce<\/span><span> <\/span><span># Warn once per Python process<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>-<\/span><span>Wignore<\/span><span> <\/span><span># Never warn<\/span><\/code><\/li>\n \n \n \n <\/ol><\/pre>\n<p>action \u540d\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u7f29\u5199\uff0c\u89e3\u91ca\u5668\u5c06\u4f1a\u89e3\u6790\u4e3a\u5408\u9002\u7684\u540d\u79f0\u3002\u4f8b\u5982\uff0c<code>-Wi<\/code> \u4e0e <code>-Wignore<\/code> \u76f8\u540c\u3002<\/p>\n<p>\u5b8c\u6574\u7684\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><code><span>action<\/span><span>:<\/span><span>message<\/span><span>:<\/span><span>category<\/span><span>:<\/span><span>module<\/span><span>:<\/span><span>lineno<\/span><\/code><\/li>\n \n \n \n <\/ol><\/pre>\n<p>\u7a7a\u5b57\u6bb5\u5339\u914d\u6240\u6709\u503c\uff1b\u5c3e\u90e8\u7684\u7a7a\u5b57\u6bb5\u53ef\u4ee5\u7701\u7565\u3002\u4f8b\u5982\uff0c<code>-W ignore::DeprecationWarning<\/code> \u5c06\u5ffd\u7565\u6240\u6709\u7684 DeprecationWarning \u8b66\u544a\u3002<\/p>\n<p><em>action<\/em> \u5b57\u6bb5\u5982\u4e0a\u6240\u8ff0\uff0c\u4f46\u53ea\u9002\u7528\u4e8e\u5339\u914d\u5176\u4f59\u5b57\u6bb5\u7684\u8b66\u544a\u3002<\/p>\n<p><em>message<\/em> \u5b57\u6bb5\u5fc5\u987b\u4e0e\u6574\u4e2a\u8b66\u544a\u4fe1\u606f\u76f8\u5339\u914d\uff1b\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002<\/p>\n<p><em>category<\/em> \u5b57\u6bb5\u4e0e\u8b66\u544a\u7c7b\u522b\u76f8\u5339\u914d\uff08<code>DeprecationWarning<\/code> \u7b49\uff09\u3002\u5fc5\u987b\u662f\u4e2a\u7c7b\u540d\uff1b\u68c0\u6d4b\u6d88\u606f\u7684\u5b9e\u9645\u8b66\u544a\u7c7b\u522b\u662f\u5426\u4e3a\u6307\u5b9a\u7c7b\u522b\u7684\u5b50\u7c7b\u3002<\/p>\n<p>The <em>module<\/em> field matches the (fully qualified) module name; this match is case-sensitive.<\/p>\n<p><em>lineno<\/em> \u5b57\u6bb5\u5339\u914d\u884c\u53f7\uff0c\u5176\u4e2d 0 \u5339\u914d\u6240\u6709\u884c\u53f7\uff0c\u76f8\u5f53\u4e8e\u7701\u7565\u4e86\u884c\u53f7\u3002<\/p>\n<p>\u53ef\u4ee5\u7ed9\u51fa\u591a\u4e2a -W \u9009\u9879\uff1b\u5f53\u67d0\u6761\u8b66\u544a\u4fe1\u606f\u5339\u914d\u4e0a\u591a\u4e2a\u9009\u9879\u65f6\uff0c\u5c06\u6267\u884c\u6700\u540e\u4e00\u4e2a\u5339\u914d\u9879\u7684\u64cd\u4f5c\u3002\u975e\u6cd5 -W \u9009\u9879\u5c06\u88ab\u5ffd\u7565\uff08\u4e0d\u8fc7\uff0c\u5728\u89e6\u53d1\u7b2c\u4e00\u6761\u8b66\u544a\u65f6\uff0c\u4f1a\u6253\u5370\u51fa\u4e00\u6761\u65e0\u6548\u9009\u9879\u7684\u8b66\u544a\u4fe1\u606f\uff09\u3002<\/p>\n<p>\u8b66\u544a\u4fe1\u606f\u8fd8\u53ef\u4ee5\u7528 PYTHONWARNINGS \u73af\u5883\u53d8\u91cf\u6765\u63a7\u5236\uff0c\u4e5f\u53ef\u4ee5\u5728 Python \u7a0b\u5e8f\u4e2d\u7528 warnings \u6a21\u5757\u8fdb\u884c\u63a7\u5236\u3002\u4f8b\u5982\uff0c warnings.filterwarnings() \u51fd\u6570\u53ef\u5bf9\u8b66\u544a\u4fe1\u606f\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/p>\n<p>\u8bf7\u53c2\u9605 \u8b66\u544a\u8fc7\u6ee4\u5668 \u548c \u8b66\u544a\u8fc7\u6ee4\u5668\u7684\u4ecb\u7ecd \u4e86\u89e3\u66f4\u591a\u7ec6\u8282\u3002<\/p>\n<p>-x<\/p>\n<p>\u8df3\u8fc7\u6e90\u4e2d\u7b2c\u4e00\u884c\uff0c\u4ee5\u5141\u8bb8\u4f7f\u7528\u975e Unix \u5f62\u5f0f\u7684 <code>#!cmd<\/code>\u3002 \u8fd9\u9002\u7528\u4e8e DOS \u4e13\u5c5e\u7684\u7834\u89e3\u64cd\u4f5c\u3002<\/p>\n<p>-X<\/p>\n<p>\u4fdd\u7559\u7528\u4e8e\u5404\u79cd\u5177\u4f53\u5b9e\u73b0\u4e13\u5c5e\u7684\u9009\u9879\u3002 CPython \u76ee\u524d\u5b9a\u4e49\u4e86\u4e0b\u5217\u53ef\u7528\u7684\u503c\uff1a<\/p>\n<ul>\n<li>\n<p><code>-X faulthandler<\/code> \u542f\u7528 faulthandler\uff1b<\/p>\n<\/li>\n<li>\n<p><code>-X showrefcount<\/code> \u53ef\u5728\u7a0b\u5e8f\u7ed3\u675f\u65f6\u6216\u5728\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u6bcf\u6761\u8bed\u53e5\u540e\uff0c\u8f93\u51fa\u603b\u7684\u5f15\u7528\u8ba1\u6570\u548c\u4f7f\u7528\u7684\u5185\u5b58\u5757\u6570\u3002\u8fd9\u53ea\u9002\u7528\u4e8e \u8c03\u8bd5\u7248\u672c\u3002<\/p>\n<\/li>\n<li>\n<p><code>-X tracemalloc<\/code> \u4f7f\u7528 tracemalloc \u6a21\u5757\u542f\u52a8\u5bf9 Python \u5185\u5b58\u5206\u914d\u7684\u8ddf\u8e2a\u3002 \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u6700\u8fd1\u7684\u5e27\u4f1a\u4fdd\u5b58\u5728\u8ddf\u8e2a\u7684\u56de\u6eaf\u4fe1\u606f\u4e2d\u3002 \u4f7f\u7528 <code>-X tracemalloc=NFRAME<\/code> \u4ee5\u542f\u52a8\u9650\u5b9a\u56de\u6eaf <em>NFRAME<\/em> \u5e27\u7684\u8ddf\u8e2a\u3002 \u8bf7\u53c2\u9605 tracemalloc.start() \u4e86\u89e3\u8be6\u60c5\u3002<\/p>\n<\/li>\n<li>\n<p><code>-X int_max_str_digits<\/code> configures the integer string conversion length limitation. See also PYTHONINTMAXSTRDIGITS.<\/p>\n<\/li>\n<li>\n<p><code>-X importtime<\/code> \u663e\u793a\u6bcf\u6b21\u5bfc\u5165\u8017\u8d39\u7684\u65f6\u95f4\u3002 \u5b83\u4f1a\u663e\u793a\u6a21\u5757\u540d\u79f0\uff0c\u7d2f\u8ba1\u65f6\u95f4\uff08\u5305\u62ec\u5d4c\u5957\u7684\u5bfc\u5165\uff09\u548c\u81ea\u8eab\u65f6\u95f4\uff08\u6392\u9664\u5d4c\u5957\u7684\u5bfc\u5165\uff09\u3002 \u8bf7\u6ce8\u610f\u5b83\u7684\u8f93\u51fa\u5728\u591a\u7ebf\u7a0b\u5e94\u7528\u7a0b\u5e8f\u4e2d\u53ef\u80fd\u4f1a\u51fa\u9519\u3002 \u5178\u578b\u7528\u6cd5\u5982 <code>python3 -X importtime -c 'import asyncio'<\/code>\u3002 \u53e6\u8bf7\u53c2\u9605 PYTHONPROFILEIMPORTTIME\u3002<\/p>\n<\/li>\n<li>\n<p><code>-X dev<\/code>: \u542f\u7528 Python \u5f00\u53d1\u6a21\u5f0f\uff0c\u5f15\u5165\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u542f\u7528\u4f1a\u5bfc\u81f4\u5f00\u9500\u8fc7\u5927\u7684\u8fd0\u884c\u65f6\u68c0\u67e5\u3002<\/p>\n<\/li>\n<li>\n<p><code>-X utf8<\/code> \u542f\u7528 Python UTF-8 \u6a21\u5f0f\u3002 <code>-X utf8=0<\/code> \u663e\u5f0f\u7981\u7528 Python UTF-8 \u6a21\u5f0f (\u5373\u4fbf\u5df2\u81ea\u52a8\u542f\u7528)\u3002<\/p>\n<\/li>\n<li>\n<p><code>-X pycache_prefix=PATH<\/code> \u5141\u8bb8\u5c06 <code>.pyc<\/code> \u6587\u4ef6\u5199\u5165\u4ee5\u7ed9\u5b9a\u76ee\u5f55\u4e3a\u6839\u7684\u5e76\u884c\u6811\uff0c\u800c\u4e0d\u662f\u4ee3\u7801\u6811\u3002\u53e6\u89c1 PYTHONPYCACHEPREFIX \u3002<\/p>\n<\/li>\n<li>\n<p><code>-X warn_default_encoding<\/code> issues a EncodingWarning when the locale-specific default encoding is used for opening files. See also PYTHONWARNDEFAULTENCODING.<\/p>\n<\/li>\n<li>\n<p><code>-X no_debug_ranges<\/code> disables the inclusion of the tables mapping extra location information (end line, start column offset and end column offset) to every instruction in code objects. This is useful when smaller code objects and pyc files are desired as well as suppressing the extra visual location indicators when the interpreter displays tracebacks. See also PYTHONNODEBUGRANGES.<\/p>\n<\/li>\n<li>\n<p><code>-X frozen_modules<\/code> determines whether or not frozen modules are ignored by the import machinery. A value of \u201con\u201d means they get imported and \u201coff\u201d means they are ignored. The default is \u201con\u201d if this is an installed Python (the normal case). If it\u2019s under development (running from the source tree) then the default is \u201coff\u201d. Note that the \u201cimportlib_bootstrap\u201d and \u201cimportlib_bootstrap_external\u201d frozen modules are always used, even if this flag is set to \u201coff\u201d.<\/p>\n<\/li>\n<\/ul>\n<p>\u5b83\u8fd8\u5141\u8bb8\u4f20\u5165\u4efb\u610f\u503c\u5e76\u901a\u8fc7 sys._xoptions \u5b57\u5178\u6765\u63d0\u53d6\u8fd9\u4e9b\u503c\u3002<\/p>\n<p>\u5728 3.2 \u7248\u66f4\u6539: \u589e\u52a0\u4e86 -X \u9009\u9879\u3002<\/p>\n<p>3.3 \u65b0\u7248\u529f\u80fd: <code>-X faulthandler<\/code> \u9009\u9879\u3002<\/p>\n<p>3.4 \u65b0\u7248\u529f\u80fd: <code>-X showrefcount<\/code> \u4e0e <code>-X tracemalloc<\/code> \u9009\u9879\u3002<\/p>\n<p>3.6 \u65b0\u7248\u529f\u80fd: <code>-X showalloccount<\/code> \u9009\u9879\u3002<\/p>\n<p>3.7 \u65b0\u7248\u529f\u80fd: <code>-X importtime<\/code>, <code>-X dev<\/code> \u4e0e <code>-X utf8<\/code> \u9009\u9879\u3002<\/p>\n<p>3.8 \u65b0\u7248\u529f\u80fd: <code>-X pycache_prefix<\/code> \u9009\u9879\u3002 <code>-X dev<\/code> \u9009\u9879\u73b0\u5728\u5728 io.IOBase \u6790\u6784\u51fd\u6570\u4e2d\u8bb0\u5f55 <code>close()<\/code> \u5f02\u5e38\u3002<\/p>\n<p>\u5728 3.9 \u7248\u66f4\u6539: \u4f7f\u7528 <code>-X dev<\/code> \u9009\u9879\uff0c\u5728\u5b57\u7b26\u4e32\u7f16\u7801\u548c\u89e3\u7801\u64cd\u4f5c\u65f6\u68c0\u67e5 <em>encoding<\/em> \u548c <em>errors<\/em> \u53c2\u6570\u3002<\/p>\n<p>The <code>-X showalloccount<\/code> \u9009\u9879\u5df2\u88ab\u79fb\u9664\u3002<\/p>\n<p>3.10 \u65b0\u7248\u529f\u80fd: <code>-X warn_default_encoding<\/code> \u9009\u9879\u3002<\/p>\n<p>\u4ece\u7248\u672c 3.9 \u8d77\u5f03\u7528\uff0c\u5728\u7248\u672c 3.10 \u4e2d\u79fb\u9664\u3002: The <code>-X oldparser<\/code> option.<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd: The <code>-X no_debug_ranges<\/code> option.<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd: The <code>-X frozen_modules<\/code> option.<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd: The <code>-X int_max_str_digits<\/code> option.<\/p>\n<h3>1.1.4. \u4e0d\u5e94\u5f53\u4f7f\u7528\u7684\u9009\u9879<\/h3>\n<p>-J<\/p>\n<p>\u4fdd\u7559\u7ed9 Jython \u4f7f\u7528\u3002<\/p>\n<h2>1.2. \u73af\u5883\u53d8\u91cf<\/h2>\n<p>\u8fd9\u4e9b\u73af\u5883\u53d8\u91cf\u4f1a\u5f71\u54cd Python \u7684\u884c\u4e3a\uff0c\u5b83\u4eec\u662f\u5728\u547d\u4ee4\u884c\u5f00\u5173\u4e4b\u524d\u88ab\u5904\u7406\u7684\uff0c\u4f46 -E \u6216 -I \u9664\u5916\u3002 \u6839\u636e\u7ea6\u5b9a\uff0c\u5f53\u5b58\u5728\u51b2\u7a81\u65f6\u547d\u4ee4\u884c\u5f00\u5173\u4f1a\u8986\u76d6\u73af\u5883\u53d8\u91cf\u7684\u8bbe\u7f6e\u3002<\/p>\n<p>PYTHONHOME<\/p>\n<p>\u66f4\u6539\u6807\u51c6 Python \u5e93\u7684\u4f4d\u7f6e\u3002 \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5e93\u662f\u5728 <code>*prefix*\/lib\/python*version*<\/code> \u548c <code>*exec_prefix*\/lib\/python*version*<\/code> \u4e2d\u641c\u7d22\uff0c\u5176\u4e2d <code>*prefix*<\/code> \u548c <code>*exec_prefix*<\/code> \u662f\u7531\u5b89\u88c5\u4f4d\u7f6e\u786e\u5b9a\u7684\u76ee\u5f55\uff0c\u9ed8\u8ba4\u90fd\u4f4d\u4e8e <code>\/usr\/local<\/code>\u3002<\/p>\n<p>\u5f53 PYTHONHOME \u88ab\u8bbe\u4e3a\u5355\u4e2a\u76ee\u5f55\u65f6\uff0c\u5b83\u7684\u503c\u4f1a\u540c\u65f6\u66ff\u4ee3 <code>*prefix*<\/code> \u548c <code>*exec_prefix*<\/code>\u3002 \u8981\u4e3a\u4e24\u8005\u6307\u5b9a\u4e0d\u540c\u7684\u503c\uff0c\u8bf7\u5c06 PYTHONHOME \u8bbe\u4e3a <code>*prefix*:*exec_prefix*<\/code>\u3002<\/p>\n<p>PYTHONPATH<\/p>\n<p>\u589e\u52a0\u6a21\u5757\u6587\u4ef6\u9ed8\u8ba4\u641c\u7d22\u8def\u5f84\u3002 \u6240\u7528\u683c\u5f0f\u4e0e\u7ec8\u7aef\u7684 <code>PATH<\/code> \u76f8\u540c\uff1a\u4e00\u4e2a\u6216\u591a\u4e2a\u7531 os.pathsep \u5206\u9694\u7684\u76ee\u5f55\u8def\u5f84\u540d\u79f0\uff08\u4f8b\u5982 Unix \u4e0a\u7528\u5192\u53f7\u800c\u5728 Windows \u4e0a\u7528\u5206\u53f7\uff09\u3002 \u9ed8\u8ba4\u5ffd\u7565\u4e0d\u5b58\u5728\u7684\u76ee\u5f55\u3002<\/p>\n<p>\u9664\u4e86\u666e\u901a\u76ee\u5f55\u4e4b\u5916\uff0c\u5355\u4e2a PYTHONPATH \u6761\u76ee\u53ef\u4ee5\u5f15\u7528\u5305\u542b\u7eafPython\u6a21\u5757\u7684zip\u6587\u4ef6\uff08\u6e90\u4ee3\u7801\u6216\u7f16\u8bd1\u5f62\u5f0f\uff09\u3002\u65e0\u6cd5\u4ecezip\u6587\u4ef6\u5bfc\u5165\u6269\u5c55\u6a21\u5757\u3002<\/p>\n<p>\u9ed8\u8ba4\u7d22\u5f15\u8def\u5f84\u4f9d\u8d56\u4e8e\u5b89\u88c5\u8def\u5f84\uff0c\u4f46\u901a\u5e38\u90fd\u662f\u4ee5 <code>*prefix*\/lib\/python*version*<\/code> \u5f00\u59cb (\u53c2\u89c1\u4e0a\u6587\u4e2d\u7684 PYTHONHOME)\u3002 \u5b83 <em>\u603b\u662f<\/em> \u4f1a\u88ab\u6dfb\u52a0\u5230 PYTHONPATH\u3002<\/p>\n<p>\u6709\u4e00\u4e2a\u9644\u52a0\u76ee\u5f55\u5c06\u88ab\u63d2\u5165\u5230\u7d22\u5f15\u8def\u5f84\u7684 PYTHONPATH \u4e4b\u524d\uff0c\u6b63\u5982\u4e0a\u6587\u4e2d \u63a5\u53e3\u9009\u9879 \u6240\u63cf\u8ff0\u7684\u3002 \u641c\u7d22\u8def\u5f84\u53ef\u4ee5\u5728 Python \u7a0b\u5e8f\u5185\u4f5c\u4e3a\u53d8\u91cf sys.path \u6765\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<p>PYTHONSAFEPATH<\/p>\n<p>If this is set to a non-empty string, don\u2019t prepend a potentially unsafe path to sys.path: see the -P option for details.<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONPLATLIBDIR<\/p>\n<p>\u5982\u679c\u5b83\u88ab\u8bbe\u4e3a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5219\u4f1a\u8986\u76d6 sys.platlibdir \u503c\u3002<\/p>\n<p>3.9 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONSTARTUP<\/p>\n<p>\u8fd9\u5982\u679c\u662f\u4e00\u4e2a\u53ef\u8bfb\u6587\u4ef6\u7684\u540d\u79f0\uff0c\u8be5\u6587\u4ef6\u4e2d\u7684 Python \u547d\u4ee4\u4f1a\u5728\u4ea4\u4e92\u6a21\u5f0f\u7684\u9996\u4e2a\u63d0\u793a\u7b26\u663e\u793a\u4e4b\u524d\u88ab\u6267\u884c\u3002 \u8be5\u6587\u4ef6\u4f1a\u5728\u4e0e\u4ea4\u4e92\u5f0f\u547d\u4ee4\u6267\u884c\u6240\u5728\u7684\u540c\u4e00\u547d\u540d\u7a7a\u95f4\u4e2d\u88ab\u6267\u884c\uff0c\u56e0\u6b64\u5176\u4e2d\u6240\u5b9a\u4e49\u6216\u5bfc\u5165\u7684\u5bf9\u8c61\u53ef\u4ee5\u5728\u4ea4\u4e92\u5f0f\u4f1a\u8bdd\u4e2d\u65e0\u9650\u5236\u5730\u4f7f\u7528\u3002 \u4f60\u8fd8\u53ef\u4ee5\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u4fee\u6539\u63d0\u793a\u7b26 sys.ps1 \u548c sys.ps2 \u4ee5\u53ca\u94a9\u5b50 sys.__interactivehook__\u3002<\/p>\n<p>\u4f7f\u7528 <code>filename<\/code> \u53c2\u6570\u4f1a\u5f15\u53d1 \u5ba1\u8ba1\u4e8b\u4ef6 <code>cpython.run_startup<\/code> \u3002<\/p>\n<p>PYTHONOPTIMIZE<\/p>\n<p>\u8fd9\u5982\u679c\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5b83\u5c31\u76f8\u5f53\u4e8e\u6307\u5b9a -O \u9009\u9879\u3002 \u5982\u679c\u8bbe\u4e3a\u4e00\u4e2a\u6574\u6570\uff0c\u5219\u5b83\u5c31\u76f8\u5f53\u4e8e\u591a\u6b21\u6307\u5b9a -O\u3002<\/p>\n<p>PYTHONBREAKPOINT<\/p>\n<p>\u6b64\u53d8\u91cf\u5982\u679c\u88ab\u8bbe\u5b9a\uff0c\u5b83\u4f1a\u4f7f\u7528\u52a0\u70b9\u53f7\u7684\u8def\u5f84\u6807\u8bb0\u4e00\u4e2a\u53ef\u8c03\u7528\u5bf9\u8c61\u3002 \u5305\u542b\u8be5\u53ef\u8c03\u7528\u5bf9\u8c61\u7684\u6a21\u5757\u5c06\u88ab\u5bfc\u5165\uff0c\u968f\u540e\u8be5\u53ef\u8c03\u7528\u5bf9\u8c61\u5c06\u7531 sys.breakpointhook() \u7684\u9ed8\u8ba4\u5b9e\u73b0\u6765\u8fd0\u884c\uff0c\u540e\u8005\u81ea\u8eab\u5c06\u7531\u5185\u7f6e\u7684 breakpoint() \u6765\u8c03\u7528\u3002 \u5982\u679c\u672a\u8bbe\u5b9a\uff0c\u6216\u8bbe\u5b9a\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u5219\u5b83\u76f8\u5f53\u4e8e\u503c \u201cpdb.set_trace\u201d\u3002 \u5c06\u6b64\u53d8\u91cf\u8bbe\u4e3a\u5b57\u7b26\u4e32 \u201c0\u201d \u4f1a\u5bfc\u81f4 sys.breakpointhook() \u7684\u9ed8\u8ba4\u5b9e\u73b0\u4e0d\u505a\u4efb\u4f55\u4e8b\u800c\u76f4\u63a5\u8fd4\u56de\u3002<\/p>\n<p>3.7 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONDEBUG<\/p>\n<p>\u6b64\u53d8\u91cf\u5982\u679c\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5b83\u5c31\u76f8\u5f53\u4e8e\u6307\u5b9a -d \u9009\u9879\u3002 \u5982\u679c\u8bbe\u4e3a\u4e00\u4e2a\u6574\u6570\uff0c\u5219\u5b83\u5c31\u76f8\u5f53\u4e8e\u591a\u6b21\u6307\u5b9a -d\u3002<\/p>\n<p>PYTHONINSPECT<\/p>\n<p>\u6b64\u53d8\u91cf\u5982\u679c\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5b83\u5c31\u76f8\u5f53\u4e8e\u6307\u5b9a -i \u9009\u9879\u3002<\/p>\n<p>\u6b64\u53d8\u91cf\u4e5f\u53ef\u7531 Python \u4ee3\u7801\u4f7f\u7528 os.environ \u6765\u4fee\u6539\u4ee5\u5728\u7a0b\u5e8f\u7ec8\u7ed3\u65f6\u5f3a\u5236\u68c0\u67e5\u6a21\u5f0f\u3002<\/p>\n<p>PYTHONUNBUFFERED<\/p>\n<p>\u6b64\u53d8\u91cf\u5982\u679c\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5b83\u5c31\u76f8\u5f53\u4e8e\u6307\u5b9a -u \u9009\u9879\u3002<\/p>\n<p>PYTHONVERBOSE<\/p>\n<p>\u6b64\u53d8\u91cf\u5982\u679c\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5b83\u5c31\u76f8\u5f53\u4e8e\u6307\u5b9a -v \u9009\u9879\u3002 \u5982\u679c\u8bbe\u4e3a\u4e00\u4e2a\u6574\u6570\uff0c\u5219\u5b83\u5c31\u76f8\u5f53\u4e8e\u591a\u6b21\u6307\u5b9a -v\u3002<\/p>\n<p>PYTHONCASEOK<\/p>\n<p>\u5982\u679c\u8bbe\u7f6e\u4e86\u6b64\u53d8\u91cf\uff0cPython \u5c06\u5ffd\u7565 import \u8bed\u53e5\u4e2d\u7684\u5927\u5c0f\u5199\u3002 \u8fd9\u4ec5\u5728 Windows \u548c macOS \u4e0a\u6709\u6548\u3002<\/p>\n<p>PYTHONDONTWRITEBYTECODE<\/p>\n<p>\u6b64\u53d8\u91cf\u5982\u679c\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0cPython \u5c06\u4e0d\u4f1a\u5c1d\u8bd5\u5728\u5bfc\u5165\u6e90\u6a21\u5757\u65f6\u5199\u5165 <code>.pyc<\/code> \u6587\u4ef6\u3002 \u8fd9\u76f8\u5f53\u4e8e\u6307\u5b9a -B \u9009\u9879\u3002<\/p>\n<p>PYTHONPYCACHEPREFIX<\/p>\n<p>\u5982\u679c\u8bbe\u7f6e\u4e86\u6b64\u9009\u9879\uff0cPython\u5c06\u5728\u955c\u50cf\u76ee\u5f55\u6811\u4e2d\u7684\u6b64\u8def\u5f84\u4e2d\u5199\u5165 <code>.pyc<\/code> \u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u6e90\u6811\u4e2d\u7684 <code>__pycache__<\/code> \u76ee\u5f55\u4e2d\u3002\u8fd9\u76f8\u5f53\u4e8e\u6307\u5b9a -X <code>pycache_prefix=PATH<\/code> \u9009\u9879\u3002<\/p>\n<p>3.8 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONHASHSEED<\/p>\n<p>\u5982\u679c\u6b64\u53d8\u91cf\u672a\u8bbe\u7f6e\u6216\u8bbe\u4e3a <code>random<\/code>\uff0c\u5c06\u4f7f\u7528\u4e00\u4e2a\u968f\u673a\u503c\u4f5c\u4e3a str \u548c bytes \u5bf9\u8c61\u54c8\u5e0c\u8fd0\u7b97\u7684\u79cd\u5b50\u3002<\/p>\n<p>\u5982\u679c PYTHONHASHSEED \u88ab\u8bbe\u4e3a\u4e00\u4e2a\u6574\u6570\u503c\uff0c\u5b83\u5c06\u88ab\u4f5c\u4e3a\u56fa\u5b9a\u7684\u79cd\u5b50\u6570\u7528\u6765\u751f\u6210\u54c8\u5e0c\u968f\u673a\u5316\u6240\u6db5\u76d6\u7684\u7c7b\u578b\u7684 hash() \u7ed3\u679c\u3002<\/p>\n<p>\u5b83\u7684\u76ee\u7684\u662f\u5141\u8bb8\u53ef\u590d\u73b0\u7684\u54c8\u5e0c\u8fd0\u7b97\uff0c\u4f8b\u5982\u7528\u4e8e\u89e3\u91ca\u5668\u672c\u8eab\u7684\u81ea\u6211\u68c0\u6d4b\uff0c\u6216\u5141\u8bb8\u4e00\u7ec4 python \u8fdb\u7a0b\u5171\u4eab\u54c8\u5e0c\u503c\u3002<\/p>\n<p>\u8be5\u6574\u6570\u5fc5\u987b\u4e3a\u4e00\u4e2a [0,4294967295] \u8303\u56f4\u5185\u7684\u5341\u8fdb\u5236\u6570\u3002 \u6307\u5b9a\u6570\u503c 0 \u5c06\u7981\u7528\u54c8\u5e0c\u968f\u673a\u5316\u3002<\/p>\n<p>3.2.3 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONINTMAXSTRDIGITS<\/p>\n<p>If this variable is set to an integer, it is used to configure the interpreter\u2019s global integer string conversion length limitation.<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONIOENCODING<\/p>\n<p>\u5982\u679c\u6b64\u53d8\u91cf\u5728\u8fd0\u884c\u89e3\u91ca\u5668\u4e4b\u524d\u88ab\u8bbe\u7f6e\uff0c\u5b83\u4f1a\u8986\u76d6\u901a\u8fc7 <code>encodingname:errorhandler<\/code> \u8bed\u6cd5\u8bbe\u7f6e\u7684 stdin\/stdout\/stderr \u6240\u7528\u7f16\u7801\u3002 <code>encodingname<\/code> \u548c <code>:errorhandler<\/code> \u90e8\u5206\u90fd\u662f\u53ef\u9009\u9879\uff0c\u4e0e\u5728 str.encode() \u4e2d\u7684\u542b\u4e49\u76f8\u540c\u3002<\/p>\n<p>\u5bf9\u4e8e stderr\uff0c<code>:errorhandler<\/code> \u90e8\u5206\u4f1a\u88ab\u5ffd\u7565\uff1b\u5904\u7406\u7a0b\u5e8f\u5c06\u603b\u662f\u4e3a <code>'backslashreplace'<\/code>\u3002<\/p>\n<p>\u5728 3.4 \u7248\u66f4\u6539: \u201cencodingname\u201d \u90e8\u5206\u73b0\u5728\u662f\u53ef\u9009\u7684\u3002<\/p>\n<p>\u5728 3.6 \u7248\u66f4\u6539: \u5728 Windows \u4e0a\uff0c\u5bf9\u4e8e\u4ea4\u4e92\u5f0f\u63a7\u5236\u53f0\u7f13\u51b2\u533a\u4f1a\u5ffd\u7565\u6b64\u53d8\u91cf\u6240\u6307\u5b9a\u7684\u7f16\u7801\uff0c\u9664\u975e\u8fd8\u6307\u5b9a\u4e86 PYTHONLEGACYWINDOWSSTDIO\u3002 \u901a\u8fc7\u6807\u51c6\u6d41\u91cd\u5b9a\u5411\u7684\u6587\u4ef6\u548c\u7ba1\u9053\u5219\u4e0d\u53d7\u5176\u5f71\u54cd\u3002<\/p>\n<p>PYTHONNOUSERSITE<\/p>\n<p>\u5982\u679c\u8bbe\u7f6e\u4e86\u6b64\u53d8\u91cf\uff0cPython \u5c06\u4e0d\u4f1a\u628a \u7528\u6237 site-packages \u76ee\u5f55 \u6dfb\u52a0\u5230 sys.path\u3002<\/p>\n<p>\u53c2\u89c1<\/p>\n<p>PEP 370 \u2014 \u5206\u7528\u6237\u7684 site-packages \u76ee\u5f55<\/p>\n<p>PYTHONUSERBASE<\/p>\n<p>\u5b9a\u4e49 \u7528\u6237\u57fa\u51c6\u76ee\u5f55\uff0c\u5b83\u4f1a\u5728\u6267\u884c <code>python setup.py install --user<\/code> \u65f6\u88ab\u7528\u6765\u8ba1\u7b97 \u7528\u6237 site-packages \u76ee\u5f55 \u7684\u8def\u5f84\u4ee5\u53ca Distutils \u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<p>\u53c2\u89c1<\/p>\n<p>PEP 370 \u2014 \u5206\u7528\u6237\u7684 site-packages \u76ee\u5f55<\/p>\n<p>PYTHONEXECUTABLE<\/p>\n<p>\u5982\u679c\u8bbe\u7f6e\u4e86\u6b64\u73af\u5883\u53d8\u91cf\uff0c\u5219 <code>sys.argv[0]<\/code> \u5c06\u88ab\u8bbe\u4e3a\u6b64\u53d8\u91cf\u7684\u503c\u800c\u4e0d\u662f\u901a\u8fc7 C \u8fd0\u884c\u65f6\u6240\u83b7\u5f97\u7684\u503c\u3002 \u8fd9\u4ec5\u5728 macOS \u4e0a\u8d77\u4f5c\u7528\u3002<\/p>\n<p>PYTHONWARNINGS<\/p>\n<p>\u6b64\u53d8\u91cf\u7b49\u4ef7\u4e8e -W \u9009\u9879\u3002 \u5982\u679c\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u4ee5\u9017\u53f7\u5206\u9694\u7684\u5b57\u7b26\u4e32\uff0c\u5b83\u5c31\u76f8\u5f53\u4e8e\u591a\u6b21\u6307\u5b9a -W\uff0c\u5217\u8868\u4e2d\u540e\u51fa\u73b0\u7684\u8fc7\u6ee4\u5668\u4f18\u5148\u7ea7\u4f1a\u9ad8\u4e8e\u5217\u8868\u4e2d\u5148\u51fa\u73b0\u7684\u3002<\/p>\n<p>\u6700\u7b80\u5355\u7684\u8bbe\u7f6e\u662f\u5c06\u67d0\u4e2a\u7279\u5b9a\u64cd\u4f5c\u65e0\u6761\u4ef6\u5730\u5e94\u7528\u4e8e\u8fdb\u7a0b\u6240\u53d1\u51fa\u6240\u6709\u8b66\u544a (\u5373\u4f7f\u662f\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u5ffd\u7565\u7684\u90a3\u4e9b\u8b66\u544a):<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><code><span>PYTHONWARNINGS<\/span><span>=<\/span><span>default<\/span><span> <\/span><span># Warn once per call location<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>PYTHONWARNINGS<\/span><span>=<\/span><span>error <\/span><span># Convert to exceptions<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>PYTHONWARNINGS<\/span><span>=<\/span><span>always <\/span><span># Warn every time<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>PYTHONWARNINGS<\/span><span>=<\/span><span>module<\/span><span> <\/span><span># Warn once per calling module<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>PYTHONWARNINGS<\/span><span>=<\/span><span>once <\/span><span># Warn once per Python process<\/span><\/code><\/li>\n  \n  \n  \n  <li><code><span>PYTHONWARNINGS<\/span><span>=<\/span><span>ignore <\/span><span># Never warn<\/span><\/code><\/li>\n \n \n \n <\/ol><\/pre>\n<p>\u8bf7\u53c2\u9605 \u8b66\u544a\u8fc7\u6ee4\u5668 \u548c \u8b66\u544a\u8fc7\u6ee4\u5668\u7684\u4ecb\u7ecd \u4e86\u89e3\u66f4\u591a\u7ec6\u8282\u3002<\/p>\n<p>PYTHONFAULTHANDLER<\/p>\n<p>\u5982\u679c\u6b64\u73af\u5883\u53d8\u91cf\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0cfaulthandler.enable() \u4f1a\u5728\u542f\u52a8\u65f6\u88ab\u8c03\u7528\uff1a\u4e3a <code>SIGSEGV<\/code>, <code>SIGFPE<\/code>, <code>SIGABRT<\/code>, <code>SIGBUS<\/code> \u548c <code>SIGILL<\/code> \u7b49\u4fe1\u53f7\u5b89\u88c5\u4e00\u4e2a\u5904\u7406\u53e5\u67c4\u4ee5\u8f6c\u50a8 Python \u56de\u6eaf\u4fe1\u606f\u3002 \u6b64\u53d8\u91cf\u7b49\u4ef7\u4e8e -X <code>faulthandler<\/code> \u9009\u9879\u3002<\/p>\n<p>3.3 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONTRACEMALLOC<\/p>\n<p>\u5982\u679c\u6b64\u73af\u5883\u53d8\u91cf\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5219\u4f1a\u4f7f\u7528 tracemalloc \u6a21\u5757\u542f\u52a8\u5bf9 Python \u5185\u5b58\u5206\u914d\u7684\u8ddf\u8e2a\u3002 \u8be5\u53d8\u91cf\u7684\u503c\u662f\u4fdd\u5b58\u4e8e\u8ddf\u8e2a\u7684\u56de\u6eaf\u4fe1\u606f\u4e2d\u7684\u6700\u5927\u5e27\u6570\u3002 \u4f8b\u5982\uff0c<code>PYTHONTRACEMALLOC=1<\/code> \u53ea\u4fdd\u5b58\u6700\u8fd1\u7684\u5e27\u3002 \u8bf7\u53c2\u9605 tracemalloc.start() \u4e86\u89e3\u8be6\u60c5\u3002<\/p>\n<p>3.4 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONPROFILEIMPORTTIME<\/p>\n<p>\u5982\u679c\u6b64\u53d8\u91cf\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0cPython \u5c06\u663e\u793a\u6bcf\u6b21\u5bfc\u5165\u82b1\u8d39\u4e86\u591a\u957f\u65f6\u95f4\u3002 \u6b64\u53d8\u91cf\u5b8c\u5168\u7b49\u4ef7\u4e8e\u5728\u547d\u4ee4\u884c\u4e3a\u8bbe\u7f6e <code>-X importtime<\/code>\u3002<\/p>\n<p>3.7 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONASYNCIODEBUG<\/p>\n<p>\u5982\u679c\u6b64\u53d8\u91cf\u88ab\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5219\u4f1a\u542f\u7528 asyncio \u6a21\u5757\u7684 \u8c03\u8bd5\u6a21\u5f0f\u3002<\/p>\n<p>3.4 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONMALLOC<\/p>\n<p>\u8bbe\u7f6e Python \u5185\u5b58\u5206\u914d\u5668\u548c\/\u6216\u5b89\u88c5\u8c03\u8bd5\u94a9\u5b50\u3002<\/p>\n<p>\u8bbe\u7f6e Python \u6240\u4f7f\u7528\u7684\u5185\u5b58\u5206\u914d\u5668\u65cf\u7fa4\uff1a<\/p>\n<ul>\n<li>\n<p><code>default<\/code>: \u4f7f\u7528 \u9ed8\u8ba4\u5185\u5b58\u5206\u914d\u5668\u3002<\/p>\n<\/li>\n<li>\n<p><code>malloc<\/code>: \u5bf9\u6240\u6709\u57df (<code>PYMEM_DOMAIN_RAW<\/code>, <code>PYMEM_DOMAIN_MEM<\/code>, <code>PYMEM_DOMAIN_OBJ<\/code>) \u4f7f\u7528 C \u5e93\u7684 <code>malloc()<\/code> \u51fd\u6570\u3002<\/p>\n<\/li>\n<li>\n<p><code>pymalloc<\/code>: \u5bf9 <code>PYMEM_DOMAIN_MEM<\/code> \u548c <code>PYMEM_DOMAIN_OBJ<\/code> \u57df\u4f7f\u7528 pymalloc \u5206\u914d\u5668 \u800c\u5bf9 <code>PYMEM_DOMAIN_RAW<\/code> \u57df\u4f7f\u7528 <code>malloc()<\/code> \u51fd\u6570\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5b89\u88c5 \u8c03\u8bd5\u94a9\u5b50 \uff1a<\/p>\n<ul>\n<li>\n<p><code>debug<\/code>: \u5728 \u9ed8\u8ba4\u5185\u5b58\u5206\u914d\u5668 \u4e4b\u4e0a\u5b89\u88c5\u8c03\u8bd5\u94a9\u5b50\u3002<\/p>\n<\/li>\n<li>\n<p><code>malloc_debug<\/code>: \u4e0e <code>malloc<\/code> \u76f8\u540c\u4f46\u8fd8\u4f1a\u5b89\u88c5\u8c03\u8bd5\u94a9\u5b50\u3002<\/p>\n<\/li>\n<li>\n<p><code>pymalloc_debug<\/code>: \u4e0e <code>pymalloc<\/code> \u76f8\u540c\u4f46\u8fd8\u4f1a\u5b89\u88c5\u8c03\u8bd5\u94a9\u5b50\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5728 3.7 \u7248\u66f4\u6539: \u589e\u52a0\u4e86 <code>\"default\"<\/code> \u5206\u914d\u5668\u3002<\/p>\n<p>3.6 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONMALLOCSTATS<\/p>\n<p>\u5982\u679c\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0cPython \u5c06\u5728\u6bcf\u6b21\u521b\u5efa\u65b0\u7684 pymalloc \u5bf9\u8c61\u533a\u57df\u4ee5\u53ca\u5728\u5173\u95ed\u65f6\u6253\u5370 pymalloc \u5185\u5b58\u5206\u914d\u5668 \u7684\u7edf\u8ba1\u4fe1\u606f\u3002<\/p>\n<p>\u5982\u679c PYTHONMALLOC \u73af\u5883\u53d8\u91cf\u88ab\u7528\u6765\u5f3a\u5236\u5f00\u542f C \u5e93\u7684 <code>malloc()<\/code> \u5206\u914d\u5668\uff0c\u6216\u8005\u5982\u679c Python \u7684\u914d\u7f6e\u4e0d\u652f\u6301 <code>pymalloc<\/code>\uff0c\u5219\u6b64\u53d8\u91cf\u5c06\u88ab\u5ffd\u7565\u3002<\/p>\n<p>\u5728 3.6 \u7248\u66f4\u6539: \u6b64\u53d8\u91cf\u73b0\u5728\u4e5f\u53ef\u4ee5\u88ab\u7528\u4e8e\u5728\u53d1\u5e03\u6a21\u5f0f\u4e0b\u7f16\u8bd1\u7684 Python\u3002 \u5982\u679c\u5b83\u88ab\u8bbe\u7f6e\u4e3a\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u5219\u5c06\u6ca1\u6709\u4efb\u4f55\u6548\u679c\u3002<\/p>\n<p>PYTHONLEGACYWINDOWSFSENCODING<\/p>\n<p>\u5982\u679c\u8bbe\u4e3a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u9ed8\u8ba4\u7684 filesystem encoding and error handler \u6a21\u5f0f\u5c06\u6062\u590d\u5230 3.6 \u7248\u672c\u4e4b\u524d\u7684\u503c \u201cmbcs\u201d\u548c\u201creplace\u201d\u3002 \u5426\u5219\uff0c\u5c06\u91c7\u7528\u65b0\u7684\u9ed8\u8ba4\u503c\u201cutf-8\u201d\u548c\u201csurrogatepass\u201d\u3002<\/p>\n<p>\u8fd9\u4e5f\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u901a\u8fc7 sys._enablelegacywindowsfsencoding() \u6765\u542f\u7528\u3002<\/p>\n<p>\u53ef\u7528\u6027: Windows\u3002<\/p>\n<p>3.6 \u65b0\u7248\u529f\u80fd: \u66f4\u591a\u8be6\u60c5\u8bf7\u53c2\u9605 PEP 529\u3002<\/p>\n<p>PYTHONLEGACYWINDOWSSTDIO<\/p>\n<p>\u5982\u679c\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5219\u4e0d\u4f7f\u7528\u65b0\u7684\u63a7\u5236\u53f0\u8bfb\u53d6\u5668\u548c\u5199\u5165\u5668\u3002 \u8fd9\u610f\u5473\u7740 Unicode \u5b57\u7b26\u5c06\u6839\u636e\u6d3b\u52a8\u63a7\u5236\u53f0\u7684\u4ee3\u7801\u9875\u8fdb\u884c\u7f16\u7801\uff0c\u800c\u4e0d\u662f\u4f7f\u7528 utf-8\u3002<\/p>\n<p>\u5982\u679c\u6807\u51c6\u6d41\u88ab\u91cd\u5b9a\u5411\uff08\u5230\u6587\u4ef6\u6216\u7ba1\u9053\uff09\u800c\u4e0d\u662f\u6307\u5411\u63a7\u5236\u53f0\u7f13\u51b2\u533a\u5219\u8be5\u53d8\u91cf\u4f1a\u88ab\u5ffd\u7565\u3002<\/p>\n<p>\u53ef\u7528\u6027: Windows\u3002<\/p>\n<p>3.6 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONCOERCECLOCALE<\/p>\n<p>\u5982\u679c\u503c\u8bbe\u4e3a <code>0<\/code>\uff0c\u5c06\u5bfc\u81f4\u4e3b Python \u547d\u4ee4\u884c\u5e94\u7528\u8df3\u8fc7\u5c06\u4f20\u7edf\u7684\u57fa\u4e8e ASCII \u7684 C \u4e0e POSIX \u533a\u57df\u8bbe\u7f6e\u5f3a\u5236\u8f6c\u6362\u4e3a\u66f4\u5f3a\u5927\u7684\u57fa\u4e8e UTF-8 \u7684\u66ff\u4ee3\u65b9\u6848\u3002<\/p>\n<p>\u5982\u679c\u6b64\u53d8\u91cf <em>\u672a\u88ab<\/em> \u8bbe\u7f6e\uff08\u6216\u88ab\u8bbe\u4e3a <code>0<\/code> \u4ee5\u5916\u7684\u503c\uff09\uff0c\u5219\u8986\u76d6\u73af\u5883\u53d8\u91cf\u7684 <code>LC_ALL<\/code> \u533a\u57df\u9009\u9879\u4e5f\u4e0d\u4f1a\u88ab\u8bbe\u7f6e\uff0c\u5e76\u4e14\u62a5\u544a\u7ed9 <code>LC_CTYPE<\/code> \u7c7b\u522b\u7684\u5f53\u524d\u533a\u57df\u9009\u9879\u6216\u8005\u4e3a\u9ed8\u8ba4\u7684 <code>C<\/code> \u533a\u57df\uff0c\u6216\u8005\u4e3a\u663e\u5f0f\u6307\u660e\u7684\u57fa\u4e8e ASCII \u7684 <code>POSIX<\/code> \u533a\u57df\uff0c\u7136\u540e Python CLI \u5c06\u5728\u52a0\u8f7d\u89e3\u91ca\u5668\u8fd0\u884c\u65f6\u4e4b\u524d\u5c1d\u8bd5\u4e3a <code>LC_CTYPE<\/code> \u7c7b\u522b\u6309\u6307\u5b9a\u7684\u987a\u5e8f\u914d\u7f6e\u4e0b\u5217\u533a\u57df\u9009\u9879\uff1a<\/p>\n<ul>\n<li>\n<p><code>C.UTF-8<\/code><\/p>\n<\/li>\n<li>\n<p><code>C.utf8<\/code><\/p>\n<\/li>\n<li>\n<p><code>UTF-8<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u5982\u679c\u6210\u529f\u8bbe\u7f6e\u4e86\u4ee5\u4e0a\u533a\u57df\u7c7b\u522b\u4e2d\u7684\u4e00\u4e2a\uff0c\u5219\u521d\u59cb\u5316 Python \u8fd0\u884c\u65f6\u4e4b\u524d\u4e5f\u5c06\u5728\u5f53\u524d\u8fdb\u7a0b\u73af\u5883\u4e2d\u76f8\u5e94\u5730\u8bbe\u7f6e <code>LC_CTYPE<\/code> \u73af\u5883\u53d8\u91cf\u3002 \u8fd9\u4f1a\u786e\u4fdd\u9664\u4e86\u89e3\u91ca\u5668\u672c\u8eab\u548c\u8fd0\u884c\u4e8e\u540c\u4e00\u8fdb\u7a0b\u4e2d\u7684\u5176\u4ed6\u53ef\u611f\u77e5\u533a\u57df\u9009\u9879\u7684\u7ec4\u4ef6 (\u4f8b\u5982 GNU <code>readline<\/code> \u5e93) \u4e4b\u5916\uff0c\u8fd8\u80fd\u5728\u5b50\u8fdb\u7a0b (\u65e0\u8bba\u8fd9\u4e9b\u8fdb\u7a0b\u662f\u5426\u5728\u8fd0\u884c Python \u89e3\u91ca\u5668) \u4ee5\u53ca\u5728\u67e5\u8be2\u73af\u5883\u800c\u975e\u5f53\u524d C \u533a\u57df\u7684\u64cd\u4f5c (\u4f8b\u5982 Python \u81ea\u5df1\u7684 locale.getdefaultlocale()) \u4e2d\u770b\u5230\u66f4\u65b0\u7684\u8bbe\u7f6e\u3002<\/p>\n<p>(\u663e\u5f0f\u5730\u6216\u901a\u8fc7\u4e0a\u8ff0\u7684\u9690\u5f0f\u533a\u57df\u5f3a\u5236\u8f6c\u6362) \u914d\u7f6e\u5176\u4e2d\u4e00\u4e2a\u533a\u57df\u9009\u9879\u5c06\u81ea\u52a8\u4e3a sys.stdin \u548c sys.stdout \u542f\u7528 <code>surrogateescape<\/code> \u9519\u8bef\u5904\u7406\u53e5\u67c4 (sys.stderr \u4f1a\u7ee7\u7eed\u4f7f\u7528 <code>backslashreplace<\/code> \u5982\u540c\u5728\u4efb\u4f55\u5176\u4ed6\u533a\u57df\u9009\u9879\u4e2d\u4e00\u6837)\u3002 \u8fd9\u79cd\u6d41\u5904\u7406\u884c\u4e3a\u53ef\u4ee5\u6309\u901a\u5e38\u65b9\u5f0f\u4f7f\u7528 PYTHONIOENCODING \u6765\u8986\u76d6\u3002<\/p>\n<p>\u51fa\u4e8e\u8c03\u8bd5\u76ee\u7684\uff0c\u5982\u679c\u6fc0\u6d3b\u4e86\u533a\u57df\u5f3a\u5236\u8f6c\u6362\uff0c\u6216\u8005\u5982\u679c\u5f53 Python \u8fd0\u884c\u65f6\u88ab\u521d\u59cb\u5316\u65f6\u67d0\u4e2a <em>\u5e94\u8be5<\/em> \u89e6\u53d1\u5f3a\u5236\u8f6c\u6362\u7684\u533a\u57df\u9009\u9879\u4ecd\u5904\u4e8e\u6fc0\u6d3b\u72b6\u6001\u5219\u8bbe\u7f6e <code>PYTHONCOERCECLOCALE=warn<\/code> \u5c06\u5bfc\u81f4 Python \u5728 <code>stderr<\/code> \u4e0a\u53d1\u51fa\u8b66\u544a\u6d88\u606f\u3002<\/p>\n<p>\u8fd8\u8981\u6ce8\u610f\uff0c\u5373\u4f7f\u5728\u533a\u57df\u8f6c\u6362\u8f6c\u6362\u88ab\u7981\u7528\uff0c\u6216\u8005\u5728\u5176\u65e0\u6cd5\u627e\u5230\u5408\u9002\u7684\u76ee\u6807\u533a\u57df\u65f6\uff0c\u9ed8\u8ba4 PYTHONUTF8 \u4ecd\u5c06\u5728\u4f20\u7edf\u7684\u57fa\u4e8e ASCII \u7684\u533a\u57df\u4e2d\u88ab\u6fc0\u6d3b\u3002 \u5fc5\u987b\u540c\u65f6\u7981\u7528\u8fd9\u4e24\u9879\u7279\u6027\u4ee5\u5f3a\u5236\u89e3\u91ca\u5668\u4f7f\u7528 <code>ASCII<\/code> \u800c\u4e0d\u662f <code>UTF-8<\/code> \u4f5c\u4e3a\u7cfb\u7edf\u63a5\u53e3\u3002<\/p>\n<p>Availability: Unix.<\/p>\n<p>3.7 \u65b0\u7248\u529f\u80fd: \u8bf7\u53c2\u9605 PEP 538 \u4e86\u89e3\u8be6\u60c5\u3002<\/p>\n<p>PYTHONDEVMODE<\/p>\n<p>\u5982\u679c\u5c06\u6b64\u73af\u5883\u53d8\u91cf\u8bbe\u4e3a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5219\u542f\u7528 Python \u5f00\u53d1\u6a21\u5f0f\uff0c\u5f15\u5165\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u542f\u7528\u4f1a\u5bfc\u81f4\u5f00\u9500\u8fc7\u5927\u7684\u8fd0\u884c\u65f6\u68c0\u67e5\u3002<\/p>\n<p>3.7 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONUTF8<\/p>\n<p>\u5982\u679c\u8bbe\u4e3a <code>1<\/code> \uff0c\u5c06\u4f1a\u542f\u7528 Python UTF-8 \u6a21\u5f0f\u3002<\/p>\n<p>\u82e5\u8bbe\u4e3a <code>0<\/code> \uff0c\u5219\u4f1a\u7981\u7528 Python UTF-8 \u6a21\u5f0f \u3002<\/p>\n<p>\u8bbe\u7f6e\u4efb\u4f55\u5176\u4ed6\u975e\u7a7a\u5b57\u7b26\u4e32\u4f1a\u5728\u89e3\u91ca\u5668\u521d\u59cb\u5316\u671f\u95f4\u5bfc\u81f4\u9519\u8bef\u3002<\/p>\n<p>3.7 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONWARNDEFAULTENCODING<\/p>\n<p>\u5982\u679c\u8be5\u73af\u5883\u53d8\u91cf\u8bbe\u4e3a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5219\u5728\u91c7\u7528\u67d0\u5730\u533a\u9ed8\u8ba4\u7f16\u7801\u65f6\uff0c\u5c06\u4f1a\u5f15\u53d1\u4e00\u6761 EncodingWarning \u3002<\/p>\n<p>\u8bf7\u53c2\u9605 \u9009\u62e9\u6027\u7684 EncodingWarning \u6765\u4e86\u89e3\u8be6\u60c5\u3002<\/p>\n<p>3.10 \u65b0\u7248\u529f\u80fd.<\/p>\n<p>PYTHONNODEBUGRANGES<\/p>\n<p>If this variable is set, it disables the inclusion of the tables mapping extra location information (end line, start column offset and end column offset) to every instruction in code objects. This is useful when smaller code objects and pyc files are desired as well as suppressing the extra visual location indicators when the interpreter displays tracebacks.<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd.<\/p>\n<h3>1.2.1. \u8c03\u8bd5\u6a21\u5f0f\u53d8\u91cf<\/h3>\n<p>PYTHONTHREADDEBUG<\/p>\n<p>\u82e5\u8bbe\u7f6e\u6b64\u53d8\u91cf\uff0cPython \u5c06\u4f1a\u628a\u7ebf\u7a0b\u8c03\u8bd5\u4fe1\u606f\u6253\u5370\u5230 stdout\u3002<\/p>\n<p>\u9700\u8981 Python \u7684\u8c03\u8bd5\u7248\u672c\u3002<\/p>\n<p>\u4ece\u7248\u672c 3.10 \u5f00\u59cb\u6807\u8bb0\u4e3a\u8fc7\u65f6\uff0c\u5c06\u5728\u7248\u672c 3.12 \u4e2d\u79fb\u9664\u3002.<\/p>\n<p>PYTHONDUMPREFS<\/p>\n<p>\u5982\u679c\u8bbe\u7f6e\uff0cPython\u5728\u5173\u95ed\u89e3\u91ca\u5668\uff0c\u53ca\u8f6c\u50a8\u5bf9\u8c61\u548c\u5f15\u7528\u8ba1\u6570\u540e\u4ecd\u5c06\u4fdd\u6301\u6d3b\u52a8\u3002<\/p>\n<p>\u9700\u7528 --with-trace-refs \u7f16\u8bd1\u9009\u9879\u6765\u914d\u7f6e Python\u3002<\/p>\n<p>PYTHONDUMPREFSFILE=FILENAME<\/p>\n<p>If set, Python will dump objects and reference counts still alive after shutting down the interpreter into a file called <em>FILENAME<\/em>.<\/p>\n<p>\u9700\u7528 --with-trace-refs \u7f16\u8bd1\u9009\u9879\u6765\u914d\u7f6e Python\u3002<\/p>\n<p>3.11 \u65b0\u7248\u529f\u80fd.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u547d\u4ee4\u884c\u4e0e\u73af\u5883 \u4e3a\u83b7\u53d6\u5404\u79cd\u8bbe\u7f6e\u4fe1\u606f\uff0cCPython \u89e3\u6790\u5668\u4f1a\u626b\u63cf\u547d\u4ee4\u884c\u4e0e\u73af\u5883\u3002 CPython \u5b9e\u73b0\u7ec6\u8282\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-167989","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/167989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=167989"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/167989\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=167989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=167989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=167989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}