0
I have a text file, structured as follows
- 1
- Name
- CPF
- Address
- Telephone
would like to know how I do to pick up only the lines that contain integer, in case the code(identified as 1), because I am trying to make an auto increment in python Note: there is something I should do to improve this formatting, I appreciate the comments
Note: Code of writing
codigo = verifica_codigo_cliente()
nome = raw_input("Digite o nome do Cliente: ")
cpf = raw_input("Digite o CPF do Cliente: ")
endereco = raw_input("Digite o endereço do Cliente: ")
telefone = raw_input("Digite o telefone do Cliente: ")
arquivo_cliente.write(codigo)
arquivo_cliente.write("\n" + nome + "\n")
arquivo_cliente.write(cpf + "\n")
arquivo_cliente.write(endereco + "\n")
arquivo_cliente.write(telefone + "\n\n")
Function to verify the code, that’s where I got lost
def verifica_codigo_cliente():
arquivo_cliente = open("arquivo_cliente.txt", "a+")
codigos = []
for row in arquivo_cliente:
codigos.append(row)
if codigos == []:
return 1
else:
x = codigos[len]
return codigos[x]
You already know how to open and read a Python file?
– Woss
Yes, I can open the file and even read his data. the problem is that I didn’t quite understand the difference between read, readline and readlines, even after reading the documentation
– João Paulo de Souza
You can put that code in the question?
– Woss
I already put it in question
– João Paulo de Souza
Before answering, you have already considered some better format for storing the data, such as CSV?
– Woss
the file must be in txt, but if I structure it with comma after each data, it will still work?
– João Paulo de Souza