how.wtf

Executing Python scripts with a shebang

· Thomas Taylor

The shebang line informs the operating system’s shell where to find the interpreter. The program loader will execute the specified interpreter with the same arguments that were initially passed.

Add a shebang (#!) to a Python script

How to add a shebang (#!) to a Python 3 file:

1#!/usr/bin/env python3
2
3print("hello world")

In addition to the normal execution by calling the interpreter directly:

1python3 ./hello.py

the file can be called like this:

1./hello.py

Note: The executable may not have executable permissions by the user. To enable for this, simply run:

1chmod +x ./hello.py

#Python  

Reply to this post by email ↪