When I use the goto module,it works but I got an error: Exception TypeError

When I use the goto module,it works but I got an error: Exception TypeError

我安装的goto模块形式为:the module I installed

这是错误:

Exception TypeError: "argument of type 'NoneType' is not iterable" in ignored

代码如下:

from goto import goto,label

for i in range(1,10) :
    print i
    if i == 9 :
        goto .say
    else:
        pass

label .say
print "find 9"

所以这是我的代码需要使用 goto:

#coding = utf-8

import requests
import threading
from goto import goto,label

nums = ['1','2','3','4','5','6','7','8','9','0']
schars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
chars = nums + schars

xml = ".xml"
root = "192.168.1.1:1900"
threads = 500
sem = threading.Semaphore(threads)

def get200(url):
    res = requests.get(url)
    if res.status_code == 200 :
        print url

def match(filename,length) :
    if len(filename) <= (length +1):
        for char in chars :
            label.retry
            if sem.acquire :
                filename += char
                t = threading.Thread(target = get200,args = (root + filename + xml))
                t.start()
                sem.release()
                match(filename,length)
            else:
                goto.retry

    else :
        return

match('/',6)

结构化程序定理证明goto语句不是写程序所必需的
序列、selection/choice 和 repetition/iteration 这三种编程结构的某种组合足以满足图灵机可以执行的任何计算,但需要注意的是可能需要引入代码重复和其他变量.

Goto on Wikipedia

您不需要转到。时期。只要学会正确使用Python。

for i in range(1,10) :
    print i
    if i == 9 :
        print "find 9"
        break 

应用到你的实际代码中,解决方法差不多:

for char in chars :
    while True:
        if sem.acquire :
            filename += char
            t = threading.Thread(target=get200, args=(root + filename + xml))
            t.start()
            sem.release()
            match(filename,length)
            break

哪个可以更简单:

for char in chars :
    while not sem.acquire:
        continue
    filename += char
    t = threading.Thread(target= get200, args=(root + filename + xml))
    t.start()
    sem.release()
    match(filename,length)