or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Python Module / import
資訊之芽 Python 語法班 2023/04/16
鄧人豪
課程大綱 Outline
Modules
什麼是 Modules?
具體來說就是:
什麼是 Modules?
它的概念與用處就是:
import
為什麼需要 import 呢?
4 種 import 方法
1. import <模組名>
2. import <模組名> as <自訂名稱>
3. from <模組名> import <該模組內的東西>
4. from <模組名> import <該模組內的東西> as <自訂名稱>
補充:從該模組 import 全部東東
ModuleNotFoundError
解決辦法
pip install numpy
!pip install numpy
Questions?
常用 Modules
math 數學
string 字串
random 隨機
os 操作文件目錄
sys 操作執行環境
time 時間
datetime 日期與時間
strftime() Format Codes
Questions?
自己寫 Module
步驟:
.py
的 python 檔案注意:新增的 module 檔案與使用 module 的檔案要在同一個路徑下
範例:
number_list.py
的 python 檔案,假如你主要使用的檔案是main.py
,那目錄大概會長這樣:範例:
number_list.py
中定義想要的函式與變數main.py
或main.ipynb
中 import 該 module注意:假如是在
.ipnyb
檔案中 import 其他檔案,建議加上以下程式碼。避免在更改 module 內容後,
.ipynb
檔案的 kernel 中記得的仍然是舊的 module 內容IPython autoreload 參考資料
Questions?
補充
json 格式
json 是什麼?
json 格式處理
json 轉 python
json 格式處理
python 轉 json
json viewer
CSV 檔案
CSV (Comma Separated Values) 檔案是什麼?
CSV 檔案處理
將 list 資料寫入 csv 檔案
將 dictionary 資料寫入 csv 檔案
你的
output.csv
內容應該會長這樣:讀取 csv 檔案到 list 中
讀取 csv 檔案到 dictionary 中
假如我不想用 comma(逗號)分隔資料,
而是用 colon(冒號)分隔呢?
方法:在寫入時,使用
csv.writer(..., delimiter=":")
你的
output_colon_separated.csv
內容應該會長這樣:
讀取
output_colon_separated.csv
時要用csv.reader(..., delimiter=":")
Questions?
Thanks!