1. 程式人生 > >第六章 讀取純文字文件

第六章 讀取純文字文件

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
from urllib.request import urlopen
testPage=urlopen("http://www.pythonscraping.com/pages/warandpeace/chapter1.txt")
#把字串轉變為utf-8編碼
print(str(testPage.read(),'utf-8'))
#將字元轉為Unicode編碼
#content=bytes(content,'UTF-8')將字串轉變為位元組物件
#content=content.decode('UTF-8')將位元組物件從utf-8編碼改變為Unicode編碼的字串