Skip to content

Instantly share code, notes, and snippets.

@Keycatowo
Created February 1, 2022 08:54
Show Gist options
  • Save Keycatowo/9c73e5c87bb2fc21dfca3de176b99e8b to your computer and use it in GitHub Desktop.
Save Keycatowo/9c73e5c87bb2fc21dfca3de176b99e8b to your computer and use it in GitHub Desktop.
讀取txt並進行簡單逐行處理
# 讀取txt並進行簡單逐行處理
with open("filename.txt", "r") as f:
text = f.read() # 一次讀取
lines = f.readlines() # 按行讀取
data = [line.strip().split(",") for line in lines] # 去頭尾符號,以,分割成list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment