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
'Programming' 카테고리의 다른 글
[linux][펌] ctags 사용법 (0) | 2017.09.26 |
---|---|
[python] .pyc 파일은 무엇일까? (0) | 2017.09.26 |
[linux] 파이썬으로 쉘 명령어 실행하기 Execute shell command in python (0) | 2017.08.07 |
[linux] bash (쉘) 명령어 문법 Bash command syntax (0) | 2017.08.04 |
[linux] bash에서 계산하기, bash calculation (0) | 2017.08.04 |