Почему я могу запустить этот код во время отладки, но не обычно?Python

Программы на Python
Ответить
Anonymous
 Почему я могу запустить этот код во время отладки, но не обычно?

Сообщение Anonymous »

Я работаю над школьным проектом и могу прекрасно запустить этот код в режиме отладки, но при обычном запуске получаю сообщение об ошибке.

Код: Выделить всё

import linecache

# Find if senators from the same state are in the same party
def Same_State(p1, p2):
if(p1 == p2):
isSame = True # Set to true if parties match
else:
isSame = False # Set false if no match found

return isSame

# Find senators in same state
def Find_Sens(sList, c):
index2 = 0 # Used to store values in fList

fList = [] # Empty list to hold found senators

for index in range(0,  len(sList)  +   1 ) : < b r   / >                 i f ( i n d e x 2   = =   2 ) : < b r   / >                         r e t u r n   f L i s t   #   R e t u r n   l i s t   i f   b o t h   s e n a t o r s   f o u n d < b r   / >                 < b r   / >                 l i n e   =   s t r ( s L i s t [ i n d e x ] ) . s p l i t ( ' , ' ) < b r   / > < b r   / >                 m a t c h   c : < b r   / >                         c a s e   1 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' A l a b a m a ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   2 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' A l a s k a ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   3 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' A r i z o n a ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   4 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' A r k a n s a s ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   5 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' C a l i f o r n i a ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   6 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' C o l o r a d o ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   7 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' C o n n e c t i c u t ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   8 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' D e l a w a r e ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   9 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' F l o r i d a ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   1 0 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' G e o r g i a ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   1 1 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' H a w a i i ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   1 2 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' I d a h o ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   1 3 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' I l l i n o i s ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   1 4 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' I n d i a n a ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   1 5 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' I o w a ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   1 6 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' K a n s a s ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   1 7 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' K e n t u c k y ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   1 8 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' L o u i s i a n a ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   1 9 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' M a i n e ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   2 0 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' M a r y l a n d ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   2 1 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' M a s s a c h u s e t t s ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] ) < b r   / >                                         i n d e x 2   =   i n d e x 2   +   1 < b r   / >                         c a s e   2 2 : < b r   / >                                 i f ( l i n e [ 1 ]   = =   ' M i c h i g a n ' ) : < b r   / >                                         f L i s t . a p p e n d ( s L i s t [ i n d e x ] )
index2 = index2 + 1
case 23:
if(line[1] == 'Minnesota'):
fList.append(sList[index])
index2 = index2 + 1
case 24:
if(line[1] == 'Mississippi'):
fList.append(sList[index])
index2 = index2 + 1
case 25:
if(line[1] == 'Missouri'):
fList.append(sList[index])
index2 = index2 + 1
case 26:
if(line[1] == 'Montana'):
fList.append(sList[index])
index2 = index2 + 1
case 27:
if(line[1] == 'Nebraska'):
fList.append(sList[index])
index2 = index2 + 1
case 28:
if(line[1] == 'Nevada'):
fList.append(sList[index])
index2 = index2 + 1
case 29:
if(line[1] == 'New Hampshire'):
fList.append(sList[index])
index2 = index2 + 1
case 30:
if(line[1] == 'New Jersey'):
fList.append(sList[index])
index2 = index2 + 1
case 31:
if(line[1] == 'New Mexico'):
fList.append(sList[index])
index2 = index2 + 1
case 32:
if(line[1] == 'New York'):
fList.append(sList[index])
index2 = index2 + 1
case 33:
if(line[1] == 'North Carolina'):
fList.append(sList[index])
index2 = index2 + 1
case 34:
if(line[1] == 'North Dakota'):
fList.append(sList[index])
index2 = index2 + 1
case 35:
if(line[1] == 'Ohio'):
fList.append(sList[index])
index2 = index2 + 1
case 36:
if(line[1] == 'Oklahoma'):
fList.append(sList[index])
index2 = index2 + 1
case 37:
if(line[1] == 'Oregon'):
fList.append(sList[index])
index2 = index2 + 1
case 38:
if(line[1] == 'Pennsylvania'):
fList.append(sList[index])
index2 = index2 + 1
case 39:
if(line[1] == 'Rhode Island'):
fList.append(sList[index])
index2 = index2 + 1
case 40:
if(line[1] == 'South Carolina'):
fList.append(sList[index])
index2 = index2 + 1
case 41:
if(line[1] == 'South Dakota'):
fList.append(sList[index])
index2 = index2 + 1
case 42:
if(line[1] == 'Tennessee'):
fList.append(sList[index])
index2 = index2 + 1
case 43:
if(line[1] == 'Texas'):
fList.append(sList[index])
index2 = index2 + 1
case 44:
if(line[1] == 'Utah'):
fList.append(sList[index])
index2 = index2 + 1
case 45:
if(line[1] == 'Vermont'):
fList.append(sList[index])
index2 = index2 + 1
case 46:
if(line[1] == 'Virginia'):
fList.append(sList[index])
index2 = index2 + 1
case 47:
if(line[1] == 'Washington'):
fList.append(sList[index])
index2 = index2 + 1
case 48:
if(line[1] == 'West Virginia'):
fList.append(sList[index])
index2 = index2 + 1
case 49:
if(line[1] == 'Wisconsin'):
fList.append(sList[index])
index2 = index2 + 1
case 50:
if(line[1] == 'Wyoming'):
fList.append(sList[index])
index2 = index2 + 1

# Grab lines from file
def Line_Grab():
empList = [] # Empty list

with open('Senate114.txt',  'r') as sen14:
for index in range(0, len(sen14.readlines()) + 1):
line = linecache.getline('Senate114.txt', index) # Read lines from file
empList.append(line) # Store lines in list
return empList # Return completed list

# Main Function
count = 1 # Used for match case in Find_Sens

sameSen = 0 # Stores senator data

senList = Line_Grab() # Grab lines from file

del senList[0] # Delete first element in list

while(count 

Подробнее здесь: [url]https://stackoverflow.com/questions/79171623/why-am-i-able-to-run-this-code-while-debugging-but-not-normally[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»