Hi all,
In Python we often use the following syntax to call the main logic of script
when it was ran:
```python
def main():
pass # whatever should be done for `python ./script.py`
if __name__ == '__main__':
main()
```
Maybe it is a time to introduce the new module level function like __main__ ?
Consider the following code:
```python
def __main__():
pass # whatever should be done for `python ./script.py`
```
It is much easy an less code to write ;)
Under-hood `Python` just will generate the following code:
```python
def __main__():
pass # whatever should be done for `python ./script.py`
# Below generated code
if __name__ == '__main__':
__main__()
```
If there are two `if __name__ == '__main__':` it is also not an issue:
```python
def __main__():
pass # whatever should be done for `python ./script.py`
def main():
pass # whatever should be done for `python ./script.py`
if __name__ == '__main__':
main()
# Below generated code
if __name__ == '__main__':
__main__()
```
Or we could require user to have only one `if __name__ == '__main__':` ...
What do you think, please share your opinion ...
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/FBT5BT7KYFVQCZYVAY6HSSWNKAVCXA5T/
Code of Conduct: http://python.org/psf/codeofconduct/