學習筆記 - Python

檔案讀取

實作時遇到了下列錯誤

1. 

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

解法:路徑前面+'r'

參考:http://jasonyychiu.blogspot.com/2019/10/python-syntaxerror-unicode-error.html

2. 

UnicodeDecodeError: 'cp950' codec can't decode byte 0xe5 in position 0: illegal multibyte sequence

解法:mod後面加上encoding="utf-8"

參考:https://oxygentw.net/blog/computer/python-file-utf8-encoding/ 

測資使用(比對答案)

記得要選cmd,不要選到PowerShell 

到要執行py的路徑下輸入(加號都要空格):

'python' + 要執行的檔案 + '<' + 要放入執行的檔案 + '>' +  要輸出的檔案

範例:

G:\其他電腦\我的 電腦 - 二代\研究\xxx\ccClub>python 合併串列.py < HW1\03\10.in > HW1\03\10m.out

比對測資:

'fc /L' +  filename1.txt + filename2.txt.

範例:

C:\Users\user\Desktop\ccCLUB\HW\1\05>fc/l 20.out 20m.out 

Py指令

pip list

:list all installed Python packages

10/26 note

List Comprehension

enumerate

zip

if else hell

Anaconda

'conda'不是內部或外部命令、可執行的程式或批次檔。

上方問題解法如下

https://ithelp.ithome.com.tw/articles/10218384

ccPJ

存檔案時如果路徑要帶參數就不能用raw string,解法如下:

http://jasonyychiu.blogspot.com/2019/10/python-syntaxerror-unicode-error.html

Colab存檔案到共享雲端的方法:

https://pythonviz.com/colab-jupyter/google-colab-notebook-file-io-csv-input-output/

https://stackoverflow.com/questions/54351852/accessing-shared-with-me-with-colab

創建時間:2022.11

留言

這個網誌中的熱門文章

如何在BigQuery內呈現類似舊版GA的事件表格

學習紀錄 - 1

面試經驗 - 2