About #!/usr/bin/env python, at least for me, it is rare to make Python only one-file. Often, there are modules, probably with top-level app.py. So, I only put shebang once.
Check out the main() function there. It's defined at the top of the file and it calls lower level functions there.
Regarding the hash bang, yes I just do it out of habit. I often use python to replace bash to write small command line tools, which in my case, often in single files.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It is always nice to see a runnable code, and if possible, IRL open source projects. Thanks.
And I also want to say, this also works regardless of being outer scoped.
main()has no real meaning. Butif __name__ == "__main__":as well as anything in__main__.pydo. main() may help in unittesting, though.#!/usr/bin/env python, at least for me, it is rare to make Python only one-file. Often, there are modules, probably with top-levelapp.py. So, I only put shebang once.Yes,
main()is just common to see. By no means it has to be calledmain().Here's an example from docker-compose:
The entry point is here
It doesn't even use the usual
if __name__ ...which calls this module
Check out the
main()function there. It's defined at the top of the file and it calls lower level functions there.Regarding the hash bang, yes I just do it out of habit. I often use python to replace bash to write small command line tools, which in my case, often in single files.