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

관련 정보