我正在使用mechanize for python来读取信息。
而不是像下面显示的那样阅读整个站点,我想从站点访问特定的行(例如,第439行)。
site = br.open('www.example.com').read()
我在使用.read()时遇到的问题是,有些站点太长,阅读这个过程需要很长时间。如果有缩短阅读时间的方法,请告诉我。
提前谢谢。
同样的代码在同一台机器上分别运行在Python3.6和Python2.7上,程序只是在一个循环中写文件,结果是python3.6比python2.7慢得多,令人惊讶。为什么会这样呢?@ubuntu18.04
# python3.6
import time
tt1 = time.time()
with open('test1.txt', 'w') as fout:
for i in range(1000000):
print(1, file=fout)
print (time.time()-tt1)
输出: 0.6536719799041
我对python和bencoding是个新手。我需要使用python为我的项目读写torrent文件。我已经导入了模块,下面是解析torrent的代码:
下面是我的模块的链接,它是的一个模块
import sys
from bencode import *
f = open('file.torrent','rb') #binary read write
for line in f:
print line,