2
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 is a file . Existing TXT records what is written inside it. And add the text that is inserted, I found this way of doing that requires it to ask 2x the name of the file. Is there any way you don’t need to call 2x the name request ?
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, as I do to create and put the text I wish inside warning that the file was created and that it 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()
This is applied in this case for the confirmation of the txt file ? The excerpt worked for part of my code served for the whole part of MOVE CREATE DELETE AND RENAME some file or directory.
It was this exception that I didn’t know how to do,/ But thanks I was able to solve the problem!
– Akros