__main__.py: Run a Directory like a Main Script

__main__.py: Run a Directory like a Main Script

If you want to run the code in a file by running the parent directory, simply rename that file to __main__.py.

In the code above, $python salutation gives the same output as $ python saluation/__main__.py.

Find a full example of this in my article: 3 Techniques to Effortlessly Import and Execute Python Modules.

.

Search

Related Posts

Related Posts

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran