python:選択したパスにglobを適用する[閉じる]

python:選択したパスにglobを適用する[閉じる]

最近、私はPythonに切り替えており、Bashと同様の方法でパディングを処理するためにPythonを適用する方法を理解することに集中しています。

# obtain path where we are mow
pwd = os.getcwd()
print("This is a directory with the script: %s" % pwd)
# join folder with the filles to be analysed to PWD
data = os.path.join(pwd,"data") 
print("This is a directory with the data %s" % data)

これで、拡張DLGを使用してDATA内のすべてのパディングをロードするためにglobをどのように適用できますか?これはうまくいきません

dirlist = glob.glob(data/"*.dlg")

ベストアンサー1

あなたは変更することができます現在の作業ディレクトリ到着データその後実行全体的な状況:

#!/bin/python
import os
import glob
# obtain path where we are mow
pwd = os.getcwd()
print("This is a directory with the script: %s" % pwd)
# join folder with the filles to be analysed to PWD
data = os.path.join(pwd,"data") 
print("This is a directory with the data %s" % data)
os.chdir(data)
files_grabbed = [glob.glob('*.dlg')]
print files_grabbed

おすすめ記事