回答編集履歴
1
追記
answer
CHANGED
@@ -3,6 +3,16 @@
|
|
3
3
|
>>> from pathlib import Path
|
4
4
|
>>>
|
5
5
|
>>> jpg_path = Path(r'D:\python\photo\cloud\jpg\test.jpg')
|
6
|
-
>>>
|
6
|
+
>>> jpg_path.parts
|
7
7
|
('D:\', 'python', 'photo', 'cloud', 'jpg', 'test.jpg')
|
8
|
+
>>>
|
9
|
+
>>> jpg_path.parts[-2]
|
10
|
+
'jpg'
|
11
|
+
>>> jpg_path.parts[-3]
|
12
|
+
'cloud'
|
13
|
+
>>> jpg_path.parts[-4]
|
14
|
+
'photo'
|
15
|
+
>>>
|
16
|
+
>>> jpg_path.parts[-4:-1]
|
17
|
+
('photo', 'cloud', 'jpg')
|
8
18
|
```
|