I am relatively new to Python, but after reading a lot of posts about using readline() and readlines(), I can't seem to figure this one out.
quotes = open("quotes.txt", "r")
#Opens the quotes file
quote = quotes.readlines()
#Uses the readlines() method to read each line of text file
lineCount = 0
for line in quote:
lineCount += 1
print("{}".format(line.strip()))
So, here I am using the readlines() method, but the problem is, this code prints every line at once.
So then I tried readline() in the code, but then the coded only prints one line, I won't show the code for this because I had no luck figuring it out.
I'm looking to print a line, increment a counter and break.
Then on the next run of code, it prints the next line and breaks.
So, in essence:
When I run my program the first time it would print:
"Quote 1" - Author
Then, on the next run it would be:
"Quote 2" - Author
Anyone who can help figure this out for me, it would be greatly appreciated.
Thanks!
Additional information:
I have compiled a list of quotes from an old podcast which is written line by line in the quotes.txt file, this is for a Twitter bot that I am currently developing using the Tweepy module. For now, I have collected a large number of quotes so I am not currently worried about the program looping back around and starting again until I get closer to that time.
Thanks all for the help already.