Python 3.1.2 (r312:79147, Nov 9 2010, 09:41:54) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> open("/home/madsc13ntist/test_file.txt", "r").readlines()[6] Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.1/codecs.py", line 300, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf8' codec can't decode byte 0xae in position 2230: unexpected code byte
可是......python3:readlines()索引問題?
Python 2.4.3 (#1, Sep 8 2010, 11:37:47) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> open("/home/madsc13ntist/test_file.txt", "r").readlines()[6] '2010-06-14 21:14:43 613 xxx.xxx.xxx.xxx 200 TCP_NC_MISS 4198 635 GET http www.thelegendssportscomplex.com 80 /thumbnails/t/sponsors/145x138/007.gif - - - DIRECT www.thelegendssportscomplex.com image/gif http://www.thelegendssportscomplex.com/ "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.1; MS-RTC LM 8)" OBSERVED "Sports/Recreation" - xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx\r\n'
沒有任何人有任何想法,爲什麼.readlines()[6]不爲Python-3工作,但確實在2.4的工作?
也...我想0xAE是®
這是一個編碼錯誤。索引與它無關(它甚至不需要評估)。 – delnan 2010-11-09 19:24:19
在Python3中使用'open(..,'rb')'來模擬Python 2.x行爲。 – jfs 2010-11-09 22:34:36