How to directly run a Python script in a *nix environment

Under Mac or Linux environment, add a comment line at the beginning of the file:

#!/usr/bin/env python3 print('hello, world')

Make the .py file executable:

$ chmod a+x hello.py

Then, run it by typing:

$ ./hello.py

You are all set!

Total Views: 3553

Search


Categories