Search notes:

Python: __name__

The predefined global variable __name__ is a string whose value corresponds to the module where it is evaluated.
If the source code that contains __name__ is executed as a script (rather than imported), the value of __name__ is __main__.
This behavior can be demonstrated with the following simple Python source file (tq84.py):
if __name__ == '__main__':
   print('This source is run as a script')
else:
   print('This source was imported, __main__ = {}'.format(__name__))
Github repository about-Python, path: /dunders/__name__/tq84.py
This script prints This source is run as a script if it is executed from the command line like so:
$ python tq84.py
Conversely, it prints This source was imported, __main__ = tq84 if it is imported from another script like so:
import tq84
Github repository about-Python, path: /dunders/__name__/import-tq84.py

See also

__name__ is one of the names that is present in the top level scope (__name__ == '__main__') as returned by dir().
Other dunders

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758199429, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/dunders/__name__/index(59): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78