How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu (/thread-41881.html) Pages:
1
2
|
RE: How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu - deanhystad - Apr-11-2024 I would start with the module as-is and just add the code from my example. See how long it takes to import. Python is pretty quick about loading modules. I've never had a 1.1 MB module, but I'm sure I regularly import modules that add up to more than that. Don't worry about 80 columns. That is for readabiliy, and nobody is going to read this code. You can place import commands anywhere in your python code but people expect them at the top of the module. It makes them easy to find. You can import the module anywhere you want to use it. After the module is imported the first time, subsequent imports reuse the same module object. RE: How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu - BillKochman - Apr-12-2024 (Apr-11-2024, 03:35 AM)deanhystad Wrote: If you can't open a text file, convert the text file to a python module. This is how you can convert your bible verse text file to a python module. Hello again, Dean. I was just trying to implement your suggestion when I ran into a new wall. I have everything set up, including a BibleVerse.py file, a command on the Main Menu of the game to access it, and an ANSI menu screen as well. Sadly -- and I kind of expected this to happen -- being as my BBS is running in a Mac Classic environment, apparently, that imposes the 32K size limit on text files, just as it does with SimpleText on Mac OS 9. As a result, the minute I tried to run the external/module on my BBS, I got a SyntaxError: "string constant too large (more than 32,767 characters)". Based on that, I would have to break the file -- which is 740K in size -- into 25 individual files, and then somehow make that function you gave me randomly select one of those twenty-five files, and then randomly select a verse string in the randomly selected file that it chose. Do you think that kind of a setup might work? And if so, exactly how would I edit the function you gave me so that it could do that? Thanks for your time and help. I appreciate it. As I said earlier, no one else has been able to offer me any kind of a solution to the SecurityException. RE: How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu - deanhystad - Apr-12-2024 Do you really need the entire file? If you had 100 verses your users would never know the difference. RE: How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu - Bronjer - Apr-24-2024 (Apr-01-2024, 09:53 PM)BillKochman Wrote: Hello. Just recently I put my BBS back online after nine years, and I am trying to write a python-based game -- for my BBS. To randomly print a quote from a text file when a user types a command on the main menu, create a function in your main.py file. Use Python's random module to select a quote from the file and print it. Integrate this function into your main menu function, associating it with the command. |