gpt4 book ai didi

python:变量在几个条件之后没有被定义

转载 作者:太空宇宙 更新时间:2023-11-04 09:21:07 24 4
gpt4 key购买 nike

出于某种原因,该程序说“开关”未定义。这是怎么回事?

#PYTHON 3.1.1
class mysrt:
def __init__(self):
self.DATA = open('ORDER.txt', 'r')
self.collect = 0
cache1 = str(self.DATA.readlines())
cache2 = []
for i in range(len(cache1)):
if cache1[i] == '*':
if self.collect == 0: self.collect = 1
elif self.collect == 1: self.collect = 0
elif self.collect == 1:
cache2.append(cache1[i])
self.ORDER = cache2
self.ARRAY = []
self.GLOBALi = 0
self.GLOBALmax = range(len(self.ORDER))
self.GLOBALc = []
self.GLOBALl = []
def sorter(self, array):
CACHE_LIST_1 = []
CACHE_LIST_2 = []
i = 0
for ORDERi in range(len(self.ORDER)):
for ARRAYi in range(len(array)):
CACHE = array[ARRAYi]
if CACHE[self.GLOBALi] == self.ORDER[ORDERi]:
CACHE_LIST_1.append(CACHE)
else:
CACHE_LIST_2.append(CACHE)
for i in range(len(CACHE_LIST_1)):
if CACHE_LIST_1[0] == CACHE_LIST_1[i] or range(len(CACHE_LIST_1)) == 1:
switch = 1
print ('1')
else:
switch = 0
print ('0')
break
if switch == 1:
self.GLOBALl += CACHE_LIST_1 + self.GLOBALc
self.GLOBALi = 0
self.GLOBALc = []
else:
self.GLOBALi += 1
self.GLOBALc += CACHE_LIST_2
mysrt.sorter(CACHE)
return (self.GLOBALl)

#GLOBALi =0
# if range(len(self.GLOBALc)) =! range(len(self.ARRAY))
array = ['ape', 'cow','dog','bat']
ORDER_FILE = []
mysort = mysrt()
print (mysort.sorter(array))

最佳答案

如果 CACHE_LIST_1 是空序列,则 switch 永远不会绑定(bind)。

关于python:变量在几个条件之后没有被定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2429637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com