지금 주작업에서는 python25 를 사용하고 있지만
언젠가는 python30 을 사용하게 될지 모르므로 취미 삼아 연습해보기로 했습니다.
그냥 생각없이 설치하면 파이썬이 기본실행이 python30 으로 바뀌어버린다는 말이 있어
Python3.0a2 설치파일을 실행시키고 Next 연타할 경우, Python 3.0이 디폴트버전이 됩니다.
기존 버전을 디폴트로 유지하고 싶으면,
Customize Python 3.0... 화면에서 Register Extentions feature를 제거하고 Next 하시면 됩니다.
조언에 따라 신중하게 설치작업을 완료했습니다 -_-)/
역시나 print 명령이 함수로 바뀐게 제일 낯설더군요.
Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print "haha"
File "<stdin>", line 1
print "haha"
^
SyntaxError: invalid syntax
>>>
여차저차 적응해서 간단히 텍스트 파싱 프로그램을 만드는데!
utf8 로 인코딩된 파일을 읽으면 무조건 에러가 나는겁니다 TㅁT) 허억
>>> open("utf8.txt").read()아니 디폴트가 cp949 면 어쩌라구 =ㅁ=);;
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python30\lib\io.py", line 1724, in read
decoder.decode(self.buffer.read(), final=True))
File "C:\Python30\lib\io.py", line 1295, in decode
output = self.decoder.decode(input, final=final)
UnicodeDecodeError: 'cp949' codec can't decode bytes in position 6-7: illegal multibyte sequence
>>>
메뉴얼을 보니 운영체제 환경설정마다 디폴트 인코딩이 달라진다는데 ~(-ㅁ-;;
나중에 꽤나 골치아프겠더라구요.
일단은 시간이 없어서
repr(str(open("utf8.txt", "rb").read(), "utf8"))
이런식으로 프로그래밍했다가 나중에 예외를 따라 라이브러리를 역추적해보니
open 함수가 io.py 란 모듈에 새롭게 추가되어있더군요.
def open(file, mode="r", buffering=None, encoding=None, errors=None,
newline=None, closefd=True):
프로토타입도 조금 변경되어있내요
repr(open("utf8.txt", encoding="utf8").read())
이런식으로 수정하면 완료입니다 -_-)/
예전 python2.x 방식에 비하면 깔끔해진 느낌입니다.
repr(open("utf8.txt").read().decode("utf8"))
햐햐


python 을 좋아하는 게임 프로그래머