这是我的代码,我不知道为什么我在终端上运行这个程序时出错。这是我的python代码python 3.5,我是curses模块的新手,无法处理此错误,提前谢谢
import urllib.request as ur
import time
import curses
def ini(i):
url = 'http://www.top4themes.com/data/out/134/6545537-superman-logo-wallpapers.jpg'
req = ur.urlopen(url)
count = 0
block_size= 1024
avg = 0
smin = []
value = False
t = []
while True:
start = time.time()
buff = req.read(block_size)
stop = time.time()
avg += len(buff)
if not buff:
break;
if (stop-start) < 0.2 :
block_size += 2048
elif (stop-start) > 0.2:
block_size -= 1024
count += 1
stdscr(1,0,"{}".format(block_size))
stdscr.refresh()
t.append(int(block_size))
if(block_size ==0):
block_size=max(t)
if __name__=="__main__":
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
try:
for i in range(10):
ini(i)
time.sleep(0.5)
finally:
curses.echo()
curses.nocbreak()
curses.endwin()
答案 0 :(得分:2)
错误指的是行stdscr(1,0,"{}".format(block_size))
。大概是你想要stdscr.addstr(1,0,"{}".format(block_size))
。