
- Jupyter 教程
- Jupyter - 首頁
- IPython
- IPython - 簡介
- IPython - 安裝
- IPython - 快速入門
- 執行和編輯Python指令碼
- IPython - 歷史命令
- IPython - 系統命令
- IPython - 命令列選項
- 動態物件自省
- IPython - I/O快取
- 設定IPython為預設Python環境
- 匯入Python Shell程式碼
- IPython - 嵌入IPython
- IPython - 魔術命令
- Jupyter
- Jupyter專案 - 概述
- Jupyter Notebook - 簡介
- 線上使用Jupyter
- 安裝和快速入門
- Jupyter Notebook - 儀表板
- Jupyter Notebook - 使用者介面
- Jupyter Notebook - 單元格型別
- Jupyter Notebook - 編輯
- Jupyter Notebook - Markdown單元格
- 單元格魔法函式
- Jupyter Notebook - 繪圖
- 轉換Notebook
- Jupyter Notebook - IPyWidgets
- QtConsole
- QtConsole - 快速入門
- QtConsole - 多行編輯
- QtConsole - 內聯圖形
- QtConsole - 儲存為Html
- QtConsole - 多個控制檯
- 連線到Jupyter Notebook
- 使用github和nbviewer
- JupyterLab
- JupyterLab - 概述
- 安裝和快速入門
- JupyterLab - 介面
- JupyterLab - 安裝R核心
- Jupyter資源
- Jupyter - 快速指南
- Jupyter - 有用資源
- Jupyter - 討論
IPython - 執行和編輯Python指令碼
在本章中,讓我們瞭解如何執行和編輯Python指令碼。
執行命令
您可以在輸入提示符中使用run命令來執行Python指令碼。run命令實際上是行魔法命令,應該寫成%run。但是,%automagic模式預設情況下始終開啟,因此您可以省略它。
In [1]: run hello.py Hello IPython
編輯命令
IPython還提供編輯魔法命令。它呼叫作業系統的預設編輯器。您可以透過Windows記事本編輯器開啟它,並可以編輯指令碼。儲存輸入後關閉它,將顯示修改後指令碼的輸出。
In [2]: edit hello.py Editing... done. Executing edited code... Hello IPython welcome to interactive computing
請注意,hello.py最初只包含一條語句,編輯後又添加了一條語句。如果未向編輯命令提供檔名,則會建立一個臨時檔案。請觀察顯示相同的以下程式碼。
In [7]: edit IPython will make a temporary file named: C:\Users\acer\AppData\Local\Temp\ipython_edit_4aa4vx8f\ipython_edit_t7i6s_er.py Editing... done. Executing edited code... magic of IPython Out[7]: 'print ("magic of IPython")'
廣告