Create a main.py File for the Core of the Application #3

Closed
opened 2022-08-19 01:08:51 +00:00 by engineerjoe440 · 0 comments

Every good project needs a place to start; right? Software is no different.

All software has to have some starting place. Windows has the "Start Button," PC games have Steam, so on... and so on...

Our application has to have some starting file; the place where other things start from. The "Pythonic" way for an app to begin is with either an app.py or main.py file that can be executed, starting the program. Sure, we can break out other files to support the main one (in fact, we'll try to do this whenever it makes sense), but we still need a robust place to start.

Our main.py file should include the following:

  • a good "docstring" (comment at the top, describing the purpose of the file)
  • a main function
  • an entrypoint

What's a main function?

Main functions are where the body of code is executed from. Generally, they look something like this:

# This is my main function...
def main():
    """Core of ComputerKeeper - The Main Application."""
    print("hello, world!")
    # more...

What's an entrypoint?

Entrypoints are the way that a program starts. We could consider this whole system as something that someone else might want to "import," or use elsewhere, right? So, we should
write our code in a way that it can be leveraged in the future.

Entrypoints allow us to run the main Python file, directly, but also skip running it if we'd rather import it somehow. They look something like this:

if __name__ == "__main__":
    # We're running the script directly!
    # We should launch the app by calling the main function...
    main()
Every good project needs a place to start; right? Software is no different. All software has to have some starting place. Windows has the "Start Button," PC games have Steam, so on... and so on... Our application has to have some starting file; the place where other things start from. The "Pythonic" way for an app to begin is with either an `app.py` or `main.py` file that can be executed, starting the program. Sure, we can break out other files to support the main one (in fact, we'll try to do this whenever it makes sense), but we still need a robust place to start. Our `main.py` file should include the following: * a good "docstring" (comment at the top, describing the purpose of the file) * a main function * an entrypoint #### What's a `main` function? Main functions are where the body of code is executed from. Generally, they look something like this: ```python # This is my main function... def main(): """Core of ComputerKeeper - The Main Application.""" print("hello, world!") # more... ``` #### What's an entrypoint? Entrypoints are the way that a program starts. We could consider this whole system as something that someone else might want to "import," or use elsewhere, right? So, we should write our code in a way that it can be leveraged in the future. Entrypoints allow us to run the main Python file, directly, but also skip running it if we'd rather import it somehow. They look something like this: ```python if __name__ == "__main__": # We're running the script directly! # We should launch the app by calling the main function... main() ```
engineerjoe440 added this to the Initial Prototype milestone 2022-08-19 01:08:51 +00:00
engineerjoe440 added the
core
enhancement
labels 2022-08-19 01:08:51 +00:00
joshb was assigned by engineerjoe440 2022-08-19 01:08:51 +00:00
joshb closed this issue 2022-08-19 02:25:42 +00:00
Sign in to join this conversation.
No description provided.