This is, to my knowledge, the official (and only) way to structure a Python project. There are two to create an executable file to start everything.
Option 1: Native Script
Many Python projects offer a Bash script (on UNIX-like systems) or a Windows .bat file that will run the python3 -m cards98 command. I see this a lot.
Option 2: Python Script
This is the method I'd recommend, as it's the most portable.
Outside of your top-level package, you can write a separate Python script, such as run.py or cards98.py, and then use that to execute your main function.
For example, in cards98/__main__.py, you can put this...
defmain():# The logic for starting your application.
if__name__=="__main__":main()
And then, outside of the cards98 package, create the file cards98.py, with the following:
This is, to my knowledge, the official (and only) way to structure a Python project. There are two to create an executable file to start everything.
Option 1: Native Script
Many Python projects offer a Bash script (on UNIX-like systems) or a Windows
.bat
file that will run thepython3 -m cards98
command. I see this a lot.Option 2: Python Script
This is the method I'd recommend, as it's the most portable.
Outside of your top-level package, you can write a separate Python script, such as
run.py
orcards98.py
, and then use that to execute your main function.For example, in
cards98/__main__.py
, you can put this...And then, outside of the
cards98
package, create the filecards98.py
, with the following:To start your Python application, just double-click
cards98.py
.P.S. Thanks for bringing up this situation. I realized I never addressed it in the book!