我安装的goto模块是:the module I installed
这是错误:
异常TypeError:“类型为'NoneType'的参数不可迭代” 忽略
以下是代码:
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)
答案 0 :(得分:2)
你不需要转到。期。只是学会正确使用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)
答案 1 :(得分:1)
结构化程序定理证明编写程序不需要goto
语句
序列,选择/选择和重复/迭代的三种编程结构的某种组合足以用于图灵机可以执行的任何计算,但需要引入代码重复和其他变量。