3

RIght now, I type "python myfile.py" to run it.

How can I type "py myfile.py" to run it? Or better, do this ./myfile.py?

Any tips?

Alex
  • 8,471
  • 26
  • 75
  • 99

2 Answers2

10

You can add this as the first line of your python script:

#!/usr/bin/env python

Which will allow you to run your script as:

./myfile.py

But you must make sure you make your python script executable:

chmod +x myfile.py
Eric Wendelin
  • 221
  • 1
  • 6
  • 5
    And if you want to skip adding the `./` place the script somewhere in your path. For extra points rename the file and skip adding the `.py` extension. – Zoredache Jun 22 '10 at 23:21
1
alias py='python'
JamesRyan
  • 8,166
  • 2
  • 25
  • 36