Using the Python Interpreter(解釋器的使用)
Invoking the Interpreter(解釋器的安裝)
The Python interpreter is usually installed as /usr/local/bin/python3.9 on those machines where it is available; putting /usr/local/bin in your Unix shell’s search path makes it possible to start it by typing the command :
自譯:Python解釋器通常安裝在機器的可用路徑為「/usr/local/bin/python3.9」,將「/usr/local/bin」置於你的UNIX shell的搜索路徑中通過鍵入「python 3.9」的命令來啟動它。
to the shell. Since the choice of the directory where the interpreter lives is an installation option, other places are possible; check with your local Python guru or system administrator. (E.g., /usr/local/python is a popular alternative location.)
自譯:由於解釋器的安裝路徑是可以自主設置的,所以你可以使用系統管理員的權限進行安裝路徑的設置(例如"/usr/local/python"是一個比較通用的安裝路徑)
On Windows machines where you have installed Python from the Microsoft Store, the python3.9 command will be available. If you have the py.exe launcher installed, you can use the py command. See Excursus: Setting environment variables for other ways to launch Python.
自譯:在Windows機器上你可以通過微軟軟體商店進行python安裝,這樣python3.9的命令可以直接被使用。如果你通過.exe執行文件安裝的話,你可以使用python命令進行使用。為了可以登錄使用python對於環境變量的設置可以參見附件。
Typing an end-of-file character (Control-D on Unix, Control-Z on Windows) at the primary prompt causes the interpreter to exit with a zero exit status. If that doesn’t work, you can exit the interpreter by typing the following command: quit().
自譯:在主命令行中輸入結束字符可以退出解釋器登錄狀態(Unix點擊Ctrl + d,Windows系統點擊Ctrl + z)。如果它不工作了,你可以通過敲擊」quit()」命令退出解釋器。
The interpreter’s line-editing features include interactive editing, history substitution and code completion on systems that support the GNU Readline library. Perhaps the quickest check to see whether command line editing is supported is typing Control-P to the first Python prompt you get. If it beeps, you have command line editing; see Appendix Interactive Input Editing and History Substitution for an introduction to the keys. If nothing appears to happen, or if ^P is echoed, command line editing isn’t available; you』ll only be able to use backspace to remove characters from the current line.
自譯:解釋器的行編輯功能包含交互式編輯、歷史替換和支持GNU讀行庫的系統上完成編碼。檢查能夠進行行編輯最好的方式是輸入Ctrl + P。
如果發出嗡鳴提醒,那麼你可以進行命令行編輯;請參閱附錄交互式輸入編輯和歷史記錄替換以了解這些鍵的介紹。
如果沒有出現任何情況,出現的是^p,那麼命令行編輯不可用;你只能使用退格鍵從當前行中刪除字符。
The interpreter operates somewhat like the Unix shell: when called with standard input connected to a tty device, it reads and executes commands interactively; when called with a file name argument or with a file as standard input, it reads and executes a script from that file.
自譯:解釋器的操作有些像Unix shell:當連接tty設備的標準輸入被調用時,它以交互的方式讀取和執行命令;當以文件名被調用或以一個文件作為標準輸入被調用時,它從哪個文件讀取並執行腳本。
A second way of starting the interpreter is python -c command [arg] ……, which executes the statement(s) in command, analogous to the shell’s -c option. Since Python statements often contain spaces or other characters that are special to the shell, it is usually advised to quote command in its entirety with single quotes.
自譯:啟動解釋器的第二種方式是輸入 python -c 命令,它會在命令中執行語句,類似於shell中的「-c」操作。由於python語句通常包含空格和其他區別於shell的其他特徵,所以通常被建議在它的整體加上單引號。
Some Python modules are also useful as scripts. These can be invoked using python -m module [arg] ……, which executes the source file for module as if you had spelled out its full name on the command line.
自譯:一些python模塊可以作為腳本使用。可以使用」python - m 模塊」來調取。如果你已經在命令行中拼出全部的名字運行後,它將當作模塊使用一樣去執行這些源文件。
When a script file is used, it is sometimes useful to be able to run the script and enter interactive mode afterwards. This can be done by passing -i before the script.
自譯:當腳本文件被使用時,它時長被用來確保運行腳本文件並且在之後進入交互模式。也可以在腳本之前通過 「-i」來完成它。
All command line options are described in Command line and environment.
自譯:所有的命令行操作命令行和環境中執行