Reading files
파이썬은 readlines() 함수를 통해 파일 전체를 읽을 수 있다.
#!/usr/bin/env python
filename = "readme.txt"
with open(filename) as fn:
content = fn.readlines()
print(content)
Writing files
w 파라미터는 파일을 쓰기 위함을 파이썬에게 알려주는 것이고,
write()함수를 통해 파일에 데이터 기록 후 close()로 파일을 닫는다.
#!/usr/bin/env python
f = open("output.txt","w")
f.write("Pythonprogramminglanugage.com, \n")
f.write("Example program.")
f.close()
'프로그래밍 > Python' 카테고리의 다른 글
Python Tutorial : Line charts [12] (0) | 2016.04.16 |
---|---|
Python Tutorial : Statistics [11] (0) | 2016.04.15 |
Python Tutorial : Dictionary [9] (0) | 2016.04.15 |
Python Tutorial : Tuples [8] (0) | 2016.04.15 |
Python Tutorial : Lists [7] (0) | 2016.04.15 |