i need to open a txt file . In txt file i have
Andrei:Popescu:Bucuresti
Maria:Popescu:Targu-Mures
....
How do I read a text file into three variable and for each line do something ? Sorry for my english.
i need to open a txt file . In txt file i have
Andrei:Popescu:Bucuresti
Maria:Popescu:Targu-Mures
....
How do I read a text file into three variable and for each line do something ? Sorry for my english.
Notice that the names are separated by a colon(:
) so add :
in split()
to split them and store them in multiple variables:
with open("filename.txt") as f:for line in f :word1,word2,word3 = line.split(":")print(word1)print(word2)print(word3)