The code:
arquivo = open(input('Nome do arquivo a ser editado:'), 'r')
texto = arquivo.readlines()
texto.append(input('Insira o texto:'))
arquivo = open(input('Nome do arquivo a ser editado:'), 'w')
arquivo.writelines(texto)
arquivo.close()
It reads an existing .TXT file that writes what is written inside it. And it adds the text that is inserted, I found this way of doing that requires that it ask for 2x the name of the file. Is there a way I do not have to call the name request 2x?
File "C:\Users\Americo\Desktop\TESTE\Trabson.py", line 51, in sys_calls
arquivo = open(input('Nome do arquivo a ser editado:'), 'r')
FileNotFoundError: [Errno 2] No such file or directory: 'teste.txt'
And also if the file does not exist, how do I create and put the text I want inside telling me that the file was created and did not exist. Another user had put in another doubt the following code snippet:
if os.path.isfile(diretorio):
...
ficheiro = open(diretorio, "w") # criamos/abrimos o ficheiro
#.... .... ... operacoes no ficheiro
ficheiro.close()
Is this applied in this case for txt file commit? The snippet worked for part of my code served for all part of MOVE CREATE DELETE AND RENAME some file or directory.