Apr-02-2024, 12:13 AM
So, to be clear, being as I already imported random, you are saying that I really don't need to add "from random import choice", being as "choice" is a part of the "random" module. Although it also sounds like you are saying to use "from random import choice" being as that is the only part that I need. BUT, if I do that, will it still randomly pick a quote each time that the loop is run, or will it do them in order, or what?
Before writing to you, I actually did add the import string, and I did place the function near the top of my main.py file.
However, as far as the rest of the code is concerned, I assumed that where your code says "with open('quote.txt', 'r') as quotes:" I am supposed to replace "quote.txt" with the actual name of the text file where all of the quotes are stored in my"strings" folder.
Sp I did that. Then I placed all of it -- minus the import call and the function -- together in the main entry part of my main.py file.
In other words, the "while True:" part is right below the "with open('quote.txt', 'r')" with the same indentation.
However, this jython installation that my BBS has does NOT like its placement, and keeps saying "Syntax Error: Invalid Syntax" with the little arrow right underneath the letter "o" in the word "open".
Quite often when I get that syntax error, it is because I have my indention wrong somewhere, or I forgot a comma, or a parenthesis. However, no matter how much, or how little, indentation I do, I still keep getting the syntax error.
Are you saying that instead of all of that other code you gave me, I can simplify things by using "random.choice(somelist or tuple)" instead, where I would replace "somelist or tuple" with the actual name of my text file? Do I need to put a print command below or above it?
I believe I may have tried something like that earlier today before I posted here, and I was unable to get it working properly.
Before writing to you, I actually did add the import string, and I did place the function near the top of my main.py file.
However, as far as the rest of the code is concerned, I assumed that where your code says "with open('quote.txt', 'r') as quotes:" I am supposed to replace "quote.txt" with the actual name of the text file where all of the quotes are stored in my"strings" folder.
Sp I did that. Then I placed all of it -- minus the import call and the function -- together in the main entry part of my main.py file.
In other words, the "while True:" part is right below the "with open('quote.txt', 'r')" with the same indentation.
However, this jython installation that my BBS has does NOT like its placement, and keeps saying "Syntax Error: Invalid Syntax" with the little arrow right underneath the letter "o" in the word "open".
Quite often when I get that syntax error, it is because I have my indention wrong somewhere, or I forgot a comma, or a parenthesis. However, no matter how much, or how little, indentation I do, I still keep getting the syntax error.
Are you saying that instead of all of that other code you gave me, I can simplify things by using "random.choice(somelist or tuple)" instead, where I would replace "somelist or tuple" with the actual name of my text file? Do I need to put a print command below or above it?
I believe I may have tried something like that earlier today before I posted here, and I was unable to get it working properly.