문서의 이전 판입니다!
# python 2.5 from __future__ import with_statement with open("hello.txt") as f: for line in f: print line # In older versions of Python, you would have needed to do this to get the same effect: f = open("hello.txt") try: for line in f: print line finally: f.close()
import codecs f = codecs.open('파일명', encoding='utf-8') for line in f: print repr(line)
f = codecs.open('test', encoding='utf-8', mode='w+') f.write(u'\u4500 blah blah blah\n')