Answer the question
In order to leave comments, you need to log in
How to parse large text in Python?
Good afternoon, there is such initial data:
a text file (txt) is given, the data in which is located in this form (formatting is done with spaces):
Иванов Иванов (rus) ООО "Белое и пушистое"
Ivanov Ivan (en) White and Fluffy LLC
Москва, Кремль, офис №15
Answer the question
In order to leave comments, you need to log in
It is not clear why this is done in python? Test?
Collect in a dictionary so that the keys are "White and fluffy" and "White and Fluffy LLC" and inside there is another dictionary with the keys "rus" and "eng", and the data respectively were "Ivanov Ivanov" and "Ivanov Ivan".
But, in general, it is better to make a parser that will add data to the database one time, and a client that will connect to the database and select the necessary data depending on the request. It will work quickly and reliably.
However, frogs. However, the cactus
The solution is so simple that posting the finished code is somehow indecent. Dig towards the .readline() method
In general, in order not to prick in the future and make life easier for people, I would listen to advice about the database if I were you. Add once to the database (you can sqlite), write a simple guevina to the database for entering, deleting and searching. Half day work.
For example, for what is now in the question:
inp = input()
f = open("yourfile", "r")
for line in f:
if inp in line:
fio = line.split(" ")
print(fio[0 ] + " " + fio[1])
What would you recommend for more or less fast parsing of such a file?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question