1 year ago
#368250
funCoder91223
Trouble reading a very large .txt file and returning a quote from it
I have a file filled with quotes, and all quotes are separated by '#'
#
"We have reason to believe that man first walked upright to free his
hands for masturbation."
― Lily Tomlin
#
"We'll cross out that bridge when we come back to it later."
#
"Well, if you can't believe what you read in a comic book, what CAN
you believe?!"
― Bullwinkle J. Moose [Jay Ward]
#
"What is the robbing of a bank compared to the FOUNDING of a bank?"
― Bertold Brecht
#
"When the going gets tough, the tough get empirical."
― Jon Carroll
I'm trying to process this huge file, and pick a random quote from it. So far I've been able to read the file, store all lines numbers where the quote begins.
But now I'm having trouble using this data to randomly pick a quote from my quotes.txt file. I'm trying to make this as memory efficient as possible, so avoiding using readlines, or linecache for example. I'm trying to use seek() and an offset? But am not entirely sure how to do so in the most efficient manner.
Not trying to use any external libraries like numpy/pandas as well.
python
file
offset
txt
seek
0 Answers
Your Answer