「Python」glob基本的な使い方

構文
glob()
引数1にパスの文字列を指定します。
ワイルドカード*などの特殊文字が使用可能。
条件を満たすパスの文字列を要素とするリスト(list型)が取得できます。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import glob
import re
import os
cft = glob.glob('C:\\study\\skill\\study\\*.txt')
print(cft)
print("クラスの型")
print(type(cft))
import glob import re import os cft = glob.glob('C:\\study\\skill\\study\\*.txt') print(cft) print("クラスの型") print(type(cft))
import glob
import re
import os

cft = glob.glob('C:\\study\\skill\\study\\*.txt')

print(cft)
print("クラスの型")
print(type(cft))

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
['C:\\study\\skill\\study\\12.txt', 'C:\\study\\skill\\study\\34.txt']
<class 'list'>
['C:\\study\\skill\\study\\12.txt', 'C:\\study\\skill\\study\\34.txt'] <class 'list'>
['C:\\study\\skill\\study\\12.txt', 'C:\\study\\skill\\study\\34.txt']
<class 'list'>

 

Python

Posted by arkgame