回答編集履歴
1
追記
test
CHANGED
@@ -31,3 +31,55 @@
|
|
31
31
|
|
32
32
|
|
33
33
|
[Wandbox](https://wandbox.org/permlink/CZEw2drZo5gS86Aa)
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
あるいはこんなのも。
|
38
|
+
|
39
|
+
```Python
|
40
|
+
|
41
|
+
import re
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
path = 'C:/Users/user_name/フォルダ1/フォルダ2/2014-2017/2017/テキスト(1500番)\10番\テキストタイトル.txt'
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
result = re.split(
|
50
|
+
|
51
|
+
r'[/(())\]+',
|
52
|
+
|
53
|
+
path
|
54
|
+
|
55
|
+
)[-4:]
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
for elem in result:
|
60
|
+
|
61
|
+
print(elem)
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
[Wandbox](https://wandbox.org/permlink/skSehswmTWvGrCqJ)
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
---
|
72
|
+
|
73
|
+
この場合scanf系の関数があればそれが一番楽なのですが、標準では用意していないようです。
|
74
|
+
|
75
|
+
> **scanf() や sscanf() と同等なものはありますか?**
|
76
|
+
|
77
|
+
> そのようなものはありません。
|
78
|
+
|
79
|
+
> [中略]
|
80
|
+
|
81
|
+
> もっと複雑な入力解析をしたいなら、C の sscanf() よりも正規表現の方が便利ですし、この処理に向いています。
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
引用元: [Python よくある質問 » プログラミング FAQ](https://docs.python.jp/3/faq/programming.html#is-there-a-scanf-or-sscanf-equivalent)
|