Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions bot/resources/tags/if-name-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ embed:
---

This is a convention for code that should run if the file is the main file of your program:

```py
def main():
...

if __name__ == "__main__":
main()
```
If the file is run directly, then the `main()` function will be run. If the file is imported, it will not run.

If the file is run directly, then the `main()` function will be run.
If the file is imported, it will not run.

For more about why you would do this and how it works, see
[`if __name__ == "__main__"`](https://pythondiscord.com/pages/guides/pydis-guides/if-name-main/).
For more about why you would do this and how it works, see [`if __name__ == "__main__"`](https://pythondiscord.com/pages/guides/pydis-guides/if-name-main/).