Computer Science/python

python 파일 입출력

바닐라스카이 2019. 7. 12. 13:30
반응형

python 파일 입출력

 

 

python에서 파일을 찾고, 파일이 없을시 except 출력, 있다면 파일을 열어서 본문을 수행하고 파일 닫고 종료.

 

        try : 
                list_file = open(list_file_name) 

        except OSError : 
                print('can\'t find '+list_file_name) 

        else : 
                with listfile : 
                        for line in listfile :
                        	# do somthing

 

반응형