1
Next, I’m making a program that I’m going to divide between the function module and the interface, and I need to use files in this project (and I can’t use classes), it turns out I need to use these files between various functions, some that will write to them, others that will just read, etc. Here a piece of the code:
arqProfessores = open("arqProfessores.txt","r+")
arqDisciplinas = open("arqDisciplinas.txt","r+")
arqAlunos = open("arqAlunos.txt","r+")
arqTurmas = open("arqTurmas.txt","r+")
def addProfessor(cpf, nome, departamento):
if cpf not in arqProfessores:
dicProfessor = {"Nome":nome, "Cpf":cpf, "Departamento":departamento}
arqProfessores = open("arqProfessores.txt","a")
arqProfessores.write(dicProfessor)
arqProfessores.close()
print("Professor cadastrado com sucesso.")
else:
print("Erro de cadastro.\nEste professor já está cadastrado no
sistema.")
def consultarProfessor(cpf):
arqProfessores = open("arqProfessores.txt","r")
if cpf in arqProfessores:
dicProfessor = arqProfessores.read(cpf) #definindo uma
variavel para a chave do dicionario de professores
for chave,elem in dicProfessor.items():
print(chave + ": " + str(elem))
arqProfessores.close()
else:
print("Este professor não é funcionário desta faculdade.")
(formatting is not like this) Anyway, for example, it has a function that I have to write in the file without deleting what is already written so the "a" in the file, but upstairs I opened as "r+", sorry ignorance, but I am very lay when the subject is file :/ What you recommend to do?