dmesg --follow
[ 70396140.000 ] posts.x: "Can I have the code that solved the CAPTCHAs?" Since my talk at @aiDotEngineer World's Fair, that's the question I get most. I've got something…  |   [ 70396200.000 ] posts.x: The talk this comes from, The Dark Arts of Web Automation, at AI Engineer World's Fair:  |   [ 70390020.000 ] posts.x: ↻ @htmx_org: some big news! after a long & intensive search process i am very happy to announce @JensenHuang as the next CEO of htmx ve…  |   [ 70241940.000 ] posts.x: ↻ @JayNagy: I’ve worked that heatshield my entire adult life. Peak career moment today To go from little 7 tile patches to a full reusabl…  |   [ 69798180.000 ] posts.x: ↻ @atlantajug: Maintainers are drowning in AI-generated slop. How do you make sure your PR isn't part of the problem? 🤖 @CoreyGallon shar…  |   [ 69798120.000 ] posts.x: ↻ @devnexus: Maintainers are drowning in AI-generated slop. How do you make sure your PR isn't part of the problem? 🤖 At #Devnexus2027, @…  |   [ 69626580.000 ] posts.x: @sentinelwayne Not following … ticketing systems are typically async, nay?  |   [ 69483540.000 ] posts.x: @sentinelwayne The chat dropped a couple of times, due to timeout. It’s just the same as if I was distracted on another screen and didn’t respond in…  |   [ 69435300.000 ] posts.x: Happy V for Vendetta Day!  |   [ 69435120.000 ] posts.x: Happy V for Vendetta Day!  |   [ 69346140.000 ] posts.x: This is a *chef’s kiss* salutation from the app in the morning. Nicely done, Claude team! 👌  |   [ 69303240.000 ] posts.x: @markfenner Nyope! It all went off perfectly, as though I had engaged in the chat myself.  |   [ 69303180.000 ] posts.x: @noelkimx Happy to share more — what are you after?  |   [ 69285720.000 ] posts.x: @noelkimx It doesn't have the password -- I logged in myself, then handed the browser session over. It's dodgy practice to ask for a customer…  |  
corey@gallon.me:~/til$

__main__.py file in a project

FIGURE 1 ⋅ __main__.py file in a project

This is, to a Python project / module, what if __name__ == '__main__ is to an individual Python file.

In Python projects, a __main__.py file is used to define what happens when a package or module is run directly as a script. It allows you to make the package executable from the command line, similar to how you would run a single Python script.

Here’s how it works:

  1. Executed when the package is run as a script: When you run a package like this:
python -m package_name

The __main__.py file inside the package is executed, just like a script. This is similar to how a main() function works in other programming languages.

  1. Entry point for a package: It serves as an entry point to the package’s functionality. You can add logic here that should be executed when the package is run.
  2. Example Structure:
my_package/
├── __init__.py
├── __main__.py
├── module1.py
└── module2.py

If you run:

python -m my_package

Python will execute the __main__.py file in my_package.

  1. Typical Use Case: It’s often used to bootstrap or run the application, e.g., starting a server, running an app, or triggering some core functionality when the package is invoked from the command line.

For example, in a __main__.py file, you might have:

def main():
    print("Running the application!")

if __name__ == "__main__":
    main()

This ensures that the package can be run both as a standalone script or imported as a module without accidentally triggering the main execution logic.

corey@gallon.me:~$ tail -f /writing Attach to the stream. An email when I have something worth sending. Replies encouraged!
corey@gallon.me:~$ ls -lt /til ↑2024-10-15 A nice workflow for creating Python projects with AI
▸2024-10-15 __main__.py file in a project ⋅ you are here
↓2024-10-15 neofetch for Linux system info summary