Python ascii 的产品,错误的开始

Python product of ascii, wrong start

我写了一个简单的脚本来检查一些域的可用性,但我不明白为什么它以 abns 开头而不是 aaaa

代码如下:

import whois
import eventlet

from itertools import product
from string import ascii_lowercase

f = open('4-letter.txt', 'w')

k = (''.join(x) for x in product(ascii_lowercase, repeat=4))


def fetch(url):
    for x in k:
        if whois.whois(x+".ro").status == "OK":
            print(x+" bad")
        else:
            f.write(x+".ro\n")


pool = eventlet.GreenPool()

for status in pool.imap(fetch, k):  
    print(status)

f.close()

您在此函数中访问全局生成器k

def fetch(url):
    for x in k:
        if whois.whois(x+".ro").status == "OK":
            print(x+" bad")
        else:
            f.write(x+".ro\n")

但是你也把k交给了pool.imap(fetch, k)。所以 k 在调用 fetch() 之前已经迭代了几个步骤。