python: variable not getting defined after several conditionals
- by Protean
For some reason this program is saying that 'switch' is not defined. What is going on?
#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))