0
print('Bem-vindo!')
print()
numero_contas = int(input('Deseja registrar quantas contas: '))
x = 0
while x < numero_contas:
x = x + 1
conta = str(input('A conta é de qual site:'))
print()
usuário = str(input('Digite o usuário:'))
senha = str(input('Digite a senha: '))
print()
arq = open('Contas.txt', 'w')
arq.write(conta)
arq.write('\n')
arq.write('Usuário: {}'.format(usuário))
arq.write('\n')
arq.write('Senha: {}'.format(senha))
arq.write('\n')
arq.close()
The problem is this: if, for example, I type 2 in the "account" variable, it asks for the information normally, but when I open the file to check, it only records the first account, if I type 3 in the "account" variable, it only records the second account, so on. How can I solve this problem?
One more basic question, how can I make the program, whenever it runs, not take the records made previously? For example: I ran the program, registered only one account. Then, I run the program again, and record two accounts, then when I go to check, the data from the first execution is gone, leaving only the data from the second execution recorded. And I want him to record all the data, without deleting the data from the previous executions, I want him to join with the next executions.
Oops, thanks, solved the problem!!!
– BRKappa
So the "a" function is not to have to open the same file several times?
– BRKappa
Just one more question, how can I open the file in certain place I wish?
– BRKappa
The
w
"erases" (sets the pointer at the beginning) when using theopen
(not in write) and generates the contents of the file again, thea
only add at the end of the file if it exists. @Brkappa– Guilherme Nascimento
It’s type for example, I want it to open the file that is in some directory, for example: C: User Accounts.txt Directory
– BRKappa
In the python open, for example: I have the file Accounts.TXT in the directory: C: Documents Pasta_test Accounts.txt. I want to open the file "Accounts.TXT" that is in this directory.
– BRKappa
@Brkappa I think it would be this in windows
open('c:/Documentos/Pasta_Teste/Contas.txt', 'a')
and this on Linuxopen('/home/user/Documentos/Pasta_Teste/Contas.txt', 'a')
– Guilherme Nascimento
Thanks, solved all my problems!!!!
– BRKappa
@Brkappa ;D for nothing
– Guilherme Nascimento