1
I want to load a dictionary where the text file .txt
contains information of the type String
, but I want the values to be loaded Inteiro
.
{'11322567498': '[0],[0]'}
Note that values are always being loaded as String
.
Code I’m using to load the values into a dictionary:
def carregar_reservas(reserva):
with open('reservas.txt') as doc:
for line in doc:
(cpf, name) = line.split()
reserva[cpf] = name
First, I would like to warn you that although the CPF is a number, the ideal is to consider it as
String
, since there are CPF numbers that start with the character0
. So when making one Typecast of the kindString
forInteiro
, it would be removed.– Vitor Subhi
To resolve your question, you can simply perform the conversion of the type value
String
for the guyInteiro
. Learn more at: https://answall.com/questions/87584/como-converter-uma-vari%C3%A1vel-string-to-int– Vitor Subhi
In this case, I tried to do this, only at the right value namely, '[0],[0]' only that ends up giving error. Valueerror: invalid literal for int() with base 10: '[0],[0]'
– UserDel