[Python tips] Convert .ipynb to .py

--

若使用 jupyter notebook 撰寫 python 程式碼,但要寫入 crontab ,或是遇到其他必需轉成 .py 檔的情況,要怎麼快速地轉檔呢?

以下分享一個使用 terminal 將 .ipynb 快速轉檔成為 .py 的方式:

1.Install package: jupyter, nbconvert

請在終端機(terminal)輸入

pip install jupyter
pip install nbconvert

如果本來就已經有安裝好這兩個 package,可以直接跳過此步驟喔!

ps. 若需檢查電腦裡安裝的 package,可以使用下列指令列出以安裝的 package

pip list

2.執行轉檔指令

jupyter nbconvert originalnotebookname.ipynb — to python

執行完成後,就會看到相同檔名的 .py 檔(originalnotebookname.py)出現在同個資料夾內囉!

--

--

Sherry’s Sharing
Sherry’s Sharing

Written by Sherry’s Sharing

Learning by doing; learning by sharing! Record my learning journeys and share my notes.

No responses yet