본문 바로가기

08. Library https://wikidocs.net/33import os 명령어 내리기os.system(시스템명령어)os.popen(시스템명령어) 작업디렉토리 알아내기os.getcwd() 작업디렉토리 바꾸기os.chdir(새경로) 경로만들기os.path.join(경로1, 경로2...) 디렉토리 생성os.mkdir(경로 [, mode=0777]) 파일 또는 디렉토리 삭제os.remove(파일경로)os.rmdir(경로) 파일 또는 디렉토리 확인os.path.exists(디렉토리경로)os.path.isfile(파일경로) import sys 명령행 인자 (python test.py arg1 arg2 arg3...)sys.argv 로 접근가능. list임. sys.copyright / sys.version / sys.stdin.. 더보기
07. File IO File IO open (파일이름, 열기모드) 파일열기모드설명'r'읽기모드로 연다(기본)'w'쓰기모드'a'첨부모드'b'이진모드't'텍스트모드 \n 같이 개행문자를 진행'+'파일 갱신을 위한 용도 tell()현재 파일에서의 커서 위치 read() - 전체를 읽음read(3) - 3byte만큼읽음readline() - line단위로 읽음readlines() - 모든 라인을 리스트로 추출 각 line 읽기f = open("test.txt", "rt")for s in f: Pickle직렬화 - 역직렬화데이터를 덤프하여 파일로 저장해 두었다가언제든 읽어와서 사용할 수 있음 저장 pickle.dump (data, filepointer)pickle.load(filepointer) 더보기
06. 예외처리 예외처리try :statementexcept [예외 타입 as 예외 변수] :예외 발생 시 statement[else :예외 발생안하면 statementfinally:예외발생유무와 상관없이 수행될 statement] raise 예외raise 예외(데이터) Exception 을 상속받아 사용자 정의 예외 class를 만들 수 있음 예외 종류Exception SystemExit StopIteration SandardError ArithmeticError FloatingPointError OverflowError ZeroDivisionError AssertionError AttributeError EnvironmentError IOError OSError EOFError ImportError KeyboardI.. 더보기