- # Read from a file:
- file = open("a_file.dat","rb")
- data = file.read()
- file.close()
- # Read from an URL:
- import urllib
- url = urllib.urlopen("<a href="http://sebsauvage.net">http://sebsauvage.net")
- html = url.read()
- url.close()
- #正确的方法如下:
- # Read from a file:
- file = open("a_file.dat","rb")
- data = file.read(10000000)
- file.close()
- # Read from an URL:
- import urllib
- url = urllib.urlopen("<a href="http://sebsauvage.net">http://sebsauvage.net")
- html = url.read(200000)
- url.close()
- #该片段来自于http://www.codesnippet.cn/detail/110120131507.html
来源: http://www.codesnippet.cn/detail/110120131507.html