티스토리 뷰
glob모듈은 윈도우의 dir명령어나 리눅스의 ls명령어와 유사한 기능을 제공함
-. glob.glob(path)
glob()함수는 경로에 대응되는 모든 파일 및 디렉토리의 리스트를 반환
'*'와 '?'사용가능하며 [,]문자를 사용한 문자열비교도 가능함
>>> glob.glob('file*') #"*"문자 사용 ['File1.MP3', 'File2.MP3'] >>> glob.glob('file?.mp3') #"?"문자 사용 ['File1.MP3', 'File2.MP3'] >>> glob.glob('file[1-9].mp3') #"[ ]"를 이용한 문자열비교 사용 ['File1.MP3', 'File2.MP3'] |
또한 경로를 주는 방식에 따라 절대경로로 결과가 나오게 할수도 있음.
>>> glob.glob('*.exe') ['python.exe', 'pythonw.exe', 'w9xpopen.exe'] >>> glob.glob(os.path.abspath('.')+'\\*.exe') ['c:\\python32\\python.exe', 'c:\\python32\\pythonw.exe', 'c:\\python32\\w9xpopen.exe'] |
-. glob.iglob(path)
glob와 동일한 동작을 수행하지만, 리스트로 결과를 반환하는 것이 아니라 이터레이터를 반환함
한번에 모든 결과를 리스트에 담지 않으므로, 결과가 매우 많은 경우에 유용하게 쓰일수 있음
>>> glob.iglob('*') <generator object iglob at 0x0101F440> >>> for t in glob.iglob('*'): print(t)
DLLs Doc include 생략... |
참조 : 빠르게 활용하는 파이썬3 프로그래밍
'Python' 카테고리의 다른 글
Python, 예외처리 (0) | 2016.04.29 |
---|---|
Python, 파일 입출력 (0) | 2016.04.29 |
Python,module os.path [파일의 경로명] (0) | 2016.04.21 |
Python, str 내장모듈 (0) | 2016.04.21 |
Python, 변수명 (0) | 2016.04.21 |
- Total
- Today
- Yesterday
- ManyToOne
- fetch join
- activeforeground
- Excel
- Composite Key
- Module
- activebackground
- IdClass
- apache
- highlightbackground
- Private
- command
- disabledforeground
- JPA
- FetchType
- borderwidth
- onetomany
- 파이썬
- 폼
- 상수
- tkinter
- Python
- indicatoron
- checkbutton
- Java
- tkinter command & bind [명령어묶기와 사건묶기] Python
- Linux
- vba
- highlightthickness
- 리눅스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |