我的python版本为3.5,进入安装目录找到帮助文档。里面的例子,源代码为啥不能执行?
例如,3.2的新功能,threading模块。有下面代码
from threading import Barrier, Thread
def get_votes(site):
ballots = conduct_election(site)
all_polls_closed.wait() # do not count until all polls are closed
totals = summarize(ballots)
publish(site, totals)
all_polls_closed = Barrier(len(sites))
for site in sites:
Thread(target=get_votes, args=(site,)).start()
根本执行不了呀
3.2模块新功能,collections模块,有下面的代码
>>> tally = Counter(dogs=5, cats=3)
>>> tally.subtract(dogs=2, cats=8) # regular subtraction
>>> tally
Counter({'dogs': 3, 'cats': -5})
也不能执行。但是我在这些操作前加collections.就可以了。变为下面这样子
import collections
tally = collections.Counter(dogs=5, cats=3)
tally.subtract(dogs=2, cats=8) # 减去
print(tally)
要引入相应的模块 不然就要写全路径
all_polls_closed = Barrier(len(sites))
这句,sites哪里有定义?