Redefining name 'elemento' from outer scope (line 55)
4import dicionario
5
6
7def encontra_elemento(elemento): 8 tabela = np.array([['H', '', '', '', '', '', '', '', '', '', '', '', 'B', 'C', 'N', 'O', 'F', 'NE'], ['LI', 'BE', '', '', '', '', '', '', '', '', '', '', 'B', 'C', 'N', 'O', 'F', 'NE'], ['NA', 'MG', '', '', '', '', '', '', '', '', '', '', 'AL', 'SI', 'P', 'S', 'CL', 'AR'], ['K', 'CA', 'SC', 'TI', 'V', 'CE', 'MN', 'FE', 'CO', 'NI', 'CU', 'ZN', 'GA', 'GE', 'AS', 'SE', 'BR', 'KR'], [
9 'RB', 'SR', 'Y', 'ZR', 'NB', 'MO', 'TC', 'RU', 'RH', 'PD', 'AG', 'CD', 'LN', 'SN', 'SB', 'TE', 'L', 'XE'], ['CS', 'BA', 'MUITO1', 'HF', 'TA', 'W', 'RE', 'OS', 'LR', 'PT', 'AU', 'HG', 'TI', 'PB', 'BI', 'PO', 'AT', 'RN'], ['FR', 'RA', 'MUITO2', 'RF', 'DB', 'SG', 'BH', 'HS', 'MT', 'DS', 'RG', 'CN', 'NH', 'FL', 'MC', 'LV', 'TS', 'OG']])
10
Redefining name 'dicionario_volta' from outer scope (line 114)
12
13
14def transforma_em_dic(lista_Tuplas):
15 dicionario_volta = dict(lista_Tuplas) 16 dicionario_volta = str(dicionario_volta) # tratar como arquivo py melhor
17 return dicionario_volta
18
Redefining name 'lista_Tuplas' from outer scope (line 79)
11 lista_Tuplas.append(tuple(listaElemento))
12
13
14def transforma_em_dic(lista_Tuplas): 15 dicionario_volta = dict(lista_Tuplas)
16 dicionario_volta = str(dicionario_volta) # tratar como arquivo py melhor
17 return dicionario_volta
Redefining name 'valorTupla' from outer scope (line 133)
1import ast
2
3
4def adiciona_a_lista(elementoTupla, valorTupla): 5 if type(valorTupla) is int:
6 listaElemento = [elementoTupla, int(valorTupla)]
7 lista_Tuplas.append(tuple(listaElemento))
Redefining name 'elementoTupla' from outer scope (line 133)
1import ast
2
3
4def adiciona_a_lista(elementoTupla, valorTupla): 5 if type(valorTupla) is int:
6 listaElemento = [elementoTupla, int(valorTupla)]
7 lista_Tuplas.append(tuple(listaElemento))
Redefining name 'Nome_Arquivo' from outer scope (line 66)
17 return dicionario_volta
18
19
20def escrever_arquivo(Nome_Arquivo, dicionario_volta): 21 with open(Nome_Arquivo, 'w') as arquivo_deTexto:
22 # bom para quando chamar dicionario em outro programa
23 nome = Nome_Arquivo.replace('.py', '').lower()
Redefining name 'dicionario_volta' from outer scope (line 114)
17 return dicionario_volta
18
19
20def escrever_arquivo(Nome_Arquivo, dicionario_volta): 21 with open(Nome_Arquivo, 'w') as arquivo_deTexto:
22 # bom para quando chamar dicionario em outro programa
23 nome = Nome_Arquivo.replace('.py', '').lower()
Redefining name 'Nome_Arquivo' from outer scope (line 66)
24 arquivo_deTexto.write(nome + ' = ' + dicionario_volta)
25
26
27def leitura(Nome_Arquivo): 28 with open(Nome_Arquivo, 'r') as arquivo_deTexto:
29 texto = arquivo_deTexto.readlines()
30 return texto
Redefining name 'texto' from outer scope (line 70)
26
27def leitura(Nome_Arquivo):
28 with open(Nome_Arquivo, 'r') as arquivo_deTexto:
29 texto = arquivo_deTexto.readlines() 30 return texto
31
32
Description
The local variable name hides the variable defined in the outer scope, making it inaccessible and might confuse.
Bad practice
filename = 'myfile.txt'
def read_file(filename): # This shadows the global `filename`
with open(filename) as file:
return file.readlines()
Preferred:
FILENAME = 'myfile.txt' # renamed global to UPPER_CASE as convention
def read_file(filename):
with open(filename) as file:
return file.readlines()
Bad practice
Another usual suspect of this is when you use the same parameter name inside a function as the global variable you are using. For example:
def run_app(app):
# This `app` shadows the global app...
app.run()
if __name__ == '__main__':
app = MyApp() # This is a global variable!
run_app(app)
Preferred:
To avoid this re-defining of a global, consider not defining app
as a global, but inside a main()
function instead:
def run_app(app):
# There is no longer a global `app` variable.
app.run()
def main():
app = MyApp()
run_app(app)
if __name__ == '__main__':
main()