I want to save the data to a python text file, but the error occurs: Filenotfounderror: [Errno 2] No such file or directory: 'agenda.txta+'

Asked

Viewed 21 times

0

#Quero criar um arquivo assim que o programa rodar pela primeira vez

def novo_contato():
    print('\n=== NOVO CONTATO ===')
    nome = input(' Nome: ')
    numero = int(input(' Número: '))
    email = input(' E-mail: ')
    try: #TRATAMENTO DE ERRO & SALVANDO CONTATO EM UM ARQUIVO
        arquivo = open("agenda.txt" "a")
        dados = f'{nome};{numero};{email}\n'
        arquivo.write(dados)
        arquivo.close()
        print('\n --- CONTATO SALVO COM SUCESSO! --- \n')
    except:
        print("\n --- ERRO AO SALVAR CONTATO!! --- \n")

  • The error being displayed to you says that the file agenda.txt does not exist in the directory that is in focus.

  • comma in the file opening, ta missing

  • How did I not see that? Thank you very much! worked right now. Always are the commas.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.