Hi all. I’m looking forward to this forum.
I’m in ex45, and in the middle of trying to make my own text-based game. In the game there are soldiers. The soldiers, unsurprisingly, hold weapons. My file structure is:
soldiers/
base_sol
cavalry
archer
weapons/
base_weap
lance
longbow
just to give an idea. In truth, there are more kinds of soldiers and many, many more kinds of weapons. I need to have these weapons imported into the soldiers who are using them. I have them all loaded in the base template. Writing imports for each one of the weapons is a tedious task. However, finding how to import all the modules in one directory (all the classes stored in the files in one folder) has proven even more time consuming.
Here is a link to a Stack Overflow question that asks just this. The accepted answer says to stick __all__ = ['string', 'of', 'all', 'files', 'that_you_are_going_to_need_to_import]
in the __init__.py
in that directory. For this, I get SyntaxError: invalid syntax
, with the carrot pointing to the second underscore after ‘all’. I see a ‘commentator’ (one who comments?) there also had a problem, but he seemed able to solve it, linking to something I could not comprehend the relevance of. (Problem!)
The questions are old, so I thought maybe all got revised or something, but it’s still boldly sitting here in the Python 3.6 documentation. I have searched the error message, getting nowhere. There are other options in the SO question, all of them involving a bunch of things I don’t know how to do. (What is glob?) This is the longhand version of saying I need help/guidance.
Thanks