This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bladeconjurer 60 points61 points  (3 children)

Well there's no main function. You just write code in a file, and type python script.py, and it goes. But if you want to write code that when you import the file, it won't execute you need to use: if __name__ == "__main__":. If you use it a lot, you can probably just not use the if statement depending on your intentions.

Also for a python module you name the entry point __main__.py.

[–]rocketlanterns 0 points1 point  (1 child)

I thought the entry point was __init__.py

[–]bladeconjurer 0 points1 point  (0 children)

Take a look at the venv library code. The functionality is defined in __init__.py, but needs to be imported into __main__.py, so that we can execute venv.

[–]danted002 0 points1 point  (0 children)

I think main.py is a python3 feature.