2
3import numpy as np
4import dicionario
5def encontra_elemento(elemento): 6 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'],['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']])
7
8 MUITO1 = ['LA','CE','PR','ND','PM','SM','EU','GD','TB','DY','HO','ER','TM','YB','LU']
24
25def leitura(Nome_Arquivo):
26 with open(Nome_Arquivo,'r') as arquivo_deTexto:
27 texto = arquivo_deTexto.readlines() 28 return texto
29
30elementos_eletro = {'F':3.98,"O":3.44,"Cl":3.16,'N':3.04,'Br':2.96,'I':2.66,'S':2.58,'Ac':0.7,"La":0.79,'Sr':0.82,'Ce':0.89,'Th':0.89,'Na':0.93,'Y':0.95,
22 nome = Nome_Arquivo.replace('.py','').lower() # bom para quando chamar dicionario em outro programa
23 arquivo_deTexto.write(nome + ' = ' + dicionario_volta)
24
25def leitura(Nome_Arquivo): 26 with open(Nome_Arquivo,'r') as arquivo_deTexto:
27 texto = arquivo_deTexto.readlines()
28 return texto
17 dicionario_volta = str(dicionario_volta) #tratar como arquivo py melhor
18 return dicionario_volta
19
20def escrever_arquivo(Nome_Arquivo,dicionario_volta): 21 with open(Nome_Arquivo,'w') as arquivo_deTexto:
22 nome = Nome_Arquivo.replace('.py','').lower() # bom para quando chamar dicionario em outro programa
23 arquivo_deTexto.write(nome + ' = ' + dicionario_volta)
17 dicionario_volta = str(dicionario_volta) #tratar como arquivo py melhor
18 return dicionario_volta
19
20def escrever_arquivo(Nome_Arquivo,dicionario_volta): 21 with open(Nome_Arquivo,'w') as arquivo_deTexto:
22 nome = Nome_Arquivo.replace('.py','').lower() # bom para quando chamar dicionario em outro programa
23 arquivo_deTexto.write(nome + ' = ' + dicionario_volta)
The local variable name hides the variable defined in the outer scope, making it inaccessible and might confuse.
filename = 'myfile.txt'
def read_file(filename): # This shadows the global `filename`
with open(filename) as file:
return file.readlines()
FILENAME = 'myfile.txt' # renamed global to UPPER_CASE as convention
def read_file(filename):
with open(filename) as file:
return file.readlines()
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)
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()