<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](../using/index.xhtml "安裝和使用 Python") | - [上一頁](floatingpoint.xhtml "15. 浮點算術:爭議和限制") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 教程](index.xhtml) ? - $('.inline-search').show(0); | # 16. 附錄 ## 16.1. 交互模式 ### 16.1.1. 錯誤處理 當發生錯誤時,解釋器會打印錯誤信息和錯誤堆棧。在交互模式下,將返回到主命令提示符;如果輸入內容來自文件,在打印錯誤堆棧之后,程序會以非零狀態退出。(這里所說的錯誤不包括 [`try`](../reference/compound_stmts.xhtml#try) 語句中由 [`except`](../reference/compound_stmts.xhtml#except) 所捕獲的異常。)有些錯誤是無條件致命的,會導致程序以非零狀態退出;比如內部邏輯矛盾或內存耗盡。所有錯誤信息都會被寫入標準錯誤流;而命令的正常輸出則被寫入標準輸出流。 將中斷字符(通常為 Control-C 或 Delete )鍵入主要或輔助提示會取消輸入并返回主提示符。 [1](#id2) 在執行命令時鍵入中斷引發的 [`KeyboardInterrupt`](../library/exceptions.xhtml#KeyboardInterrupt "KeyboardInterrupt") 異常,可以由 [`try`](../reference/compound_stmts.xhtml#try) 語句處理。 ### 16.1.2. 可執行的Python腳本 在BSD等類Unix系統上,Python腳本可以直接執行,就像shell腳本一樣,第一行添加: ``` #!/usr/bin/env python3.5 ``` (假設解釋器位于用戶的 `PATH` )腳本的開頭,并將文件設置為可執行。 `#!` 必須是文件的前兩個字符。在某些平臺上,第一行必須以Unix樣式的行結尾(`'\n'`)結束,而不是以Windows(`'\r\n'`)行結尾。請注意,散列或磅字符 `'#'` 在Python中代表注釋開始。 可以使用 **chmod** 命令為腳本提供可執行模式或權限。 ``` $ chmod +x myscript.py ``` 在Windows系統上,沒有“可執行模式”的概念。 Python安裝程序自動將 `.py` 文件與 `python.exe` 相關聯,這樣雙擊Python文件就會將其作為腳本運行。擴展也可以是 `.pyw` ,在這種情況下,會隱藏通常出現的控制臺窗口。 ### 16.1.3. 交互式啟動文件 當您以交互方式使用Python時,每次啟動解釋器時都會執行一些標準命令,這通常很方便。您可以通過將名為 [`PYTHONSTARTUP`](../using/cmdline.xhtml#envvar-PYTHONSTARTUP) 的環境變量設置為包含啟動命令的文件名來實現。這類似于Unix shell的 `.profile` 功能。 This file is only read in interactive sessions, not when Python reads commands from a script, and not when `/dev/tty` is given as the explicit source of commands (which otherwise behaves like an interactive session). It is executed in the same namespace where interactive commands are executed, so that objects that it defines or imports can be used without qualification in the interactive session. You can also change the prompts `sys.ps1` and `sys.ps2` in this file. 如果你想從當前目錄中讀取一個額外的啟動文件,你可以使用像 `if os.path.isfile('.pythonrc.py'): exec(open('.pythonrc.py').read())` 這樣的代碼在全局啟動文件中對它進行編程。如果要在腳本中使用啟動文件,則必須在腳本中顯式執行此操作: ``` import os filename = os.environ.get('PYTHONSTARTUP') if filename and os.path.isfile(filename): with open(filename) as fobj: startup_file = fobj.read() exec(startup_file) ``` ### 16.1.4. 定制模塊 Python提供了兩個鉤子來讓你自定義它:`sitecustomize` 和 `usercustomize`。要查看其工作原理,首先需要找到用戶site-packages目錄的位置。啟動Python并運行此代碼: ``` >>> import site >>> site.getusersitepackages() '/home/user/.local/lib/python3.5/site-packages' ``` 現在,您可以在該目錄中創建一個名為 `usercustomize.py` 的文件,并將所需內容放入其中。它會影響Python的每次啟動,除非它以 [`-s`](../using/cmdline.xhtml#cmdoption-s) 選項啟動,以禁用自動導入。 `sitecustomize` 以相同的方式工作,但通常由計算機管理員在全局 site-packages 目錄中創建,并在 `usercustomize` 之前被導入。有關詳情請參閱 [`site`](../library/site.xhtml#module-site "site: Module responsible for site-specific configuration.") 模塊的文檔。 腳注 [1](#id1)GNU Readline 包的問題可能會阻止這種情況。 ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](../using/index.xhtml "安裝和使用 Python") | - [上一頁](floatingpoint.xhtml "15. 浮點算術:爭議和限制") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 教程](index.xhtml) ? - $('.inline-search').show(0); | ? [版權所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 軟件基金會是一個非盈利組織。 [請捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [發現了問題](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 創建。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看