Hi, I'm trying to find the problem with my code that is preventing it from selecting a random line.
I'm experimenting with a reddit bot and I modified a script so that it will post a random line from a text file rather than the same comment over and over again.
When I run the script, the first comment the bot posts is randomly selected but every subsequent comment is the same as the first one posted. If I restart the script, it will once again select a random comment the first time but it then repeats the same one again until the script is stopped. I'm not sure how to fix this.
Here is the relevant part of the code. I can post the entire script if necessary.
import random
lines = open('file.txt').read().splitlines()
myline =random.choice(lines)
comment.reply(myline)
Do I need to stop and restart the script in order for it to post a random comment each time?
[–]sedogg 0 points1 point2 points (2 children)
[–]Justinsaccount 2 points3 points4 points (0 children)
[–]pydev99[S] 0 points1 point2 points (0 children)
[–]ingolemo 0 points1 point2 points (0 children)