Skip to content
Open
Changes from 1 commit
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
1 change: 1 addition & 0 deletions app/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello world")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

It's a best practice in Python to place executable script logic inside an if __name__ == '__main__': block.1 This prevents the code from being executed when the file is imported as a module into another script, which is crucial for code reusability and modularity.

Additionally, the file should end with a single newline character, as recommended by Python's style guide (PEP 8).2 The suggested code below addresses both points.

Suggested change
print("Hello world")
if __name__ == "__main__":
print("Hello world")

Style Guide References

Footnotes

  1. Using a if __name__ == '__main__' block allows a script to be run directly or imported as a module without executing the script's code automatically. This is a standard convention for writing executable Python scripts.

  2. PEP 8 advises ending files with a single newline character to prevent issues with some tools and to follow a universal convention.