1. sys 모듈

-sys.argv: 입력한 parameter[들]

ex) $xxxx.py foo1 foo2 --> sys.argv == [xxx.py, foo1, foo2]


2. os 모듈

-chdir('new/directory') : change directory to new directory

-getcwd() : get current working directory

-os.access(path, mode) : path의 존재/읽기/쓰기/실행 여부를 boolean으로 반환

modes (이 변수들도 os module의 일부이므로 import해야함)

1) F_OK : 존재 여부

2) R_OK : 읽기 가능 여부

3) W_OK : 쓰기 가능 여부

4) X_OK : 실행 가능 여부


- listdir('directory') : directory에 존재하는 파일 및 하위 디렉토리 이름을 string 리스트로 반환

- mkdir('path') : path라는 경로를 가지는 directory 생성

- mkdirs('high/to/low/dir') : high/to/low/dir라는 경로를 가지는 directory  생성

- remove('path/to/file') : 파일 삭제

- os.removedir('dir') : 빈 디렉토리 삭제

- os.removedirs('high/to/low/dir') : 디렉토리를 연쇄적으로 삭제\

- os.rename(old, new) : 파일 이름 수정

- os.renames(old, path/to/new) : 파일 이름 수정. 필요한 디렉터리 자동 생성

- popen('shell command', 'r') : shell command를 수행하고 파이프를 연다. from os import * 할 경우에는 popen import안됨

- system('shell command') : shell command 수행

- startfile('file/name') : os에서 지정된 프로그램으로 file/name 수행



[출처] http://devanix.tistory.com/304

+ Recent posts