博觀而約取来颤,厚積而薄發(fā)汰扭。
——蘇軾
1. 前言
在這個生活中處處都是大數(shù)據(jù)和人工智能的時代,總是能在各種角落看到 Python 的培訓廣告福铅。我招架不住敵方的猛烈攻勢萝毛,敗下陣來。經(jīng)過了一分鐘的深思熟慮滑黔,我決定利用我的三分鐘熱情進行回擊笆包,從零開始自學 Python。
2.
File Paths
文件路徑
File paths in different operating system:
不同操作系統(tǒng)中的文件路徑:
Windows:
Use the backslashes (\
) as the path separator.
使用反斜杠\
作為路徑分隔符略荡。
C:\Users\python
macOS & Linux:
Use the forward slash (/
) as the path separator.
使用正斜杠/
作為路徑分隔符色查。
/home/python/
2.1
Use pathlib
to Deal with File Paths
使用 pathlib
處理文件路徑
Always use forward slashes with pathlib
functions is a good idea. The Path()
object will convert forward slashes into the correct kind of slash for the current operating system.
在使用 pathlib
模塊的函數(shù)時,最好一直都采用正斜杠作為分隔符撞芍。Path()
對象會將正斜杠轉(zhuǎn)換為當前操作系統(tǒng)所對應的斜杠類型秧了。