Vicky
Vicky

Reputation: 51

How to run python script?

Say Suppose, the name of my python script file is hello. How the script can be executed ? Sometimes, I see that most of the python scripts are executed by (python hello.py) and sometimes (./hello.py). Which one of these executing is true? If both are same, why it is mentioned as different commands?

Upvotes: 1

Views: 218

Answers (1)

Błotosmętek
Błotosmętek

Reputation: 12927

The syntax ./hello.py is typically used on Unix-like systems (including Linux and OSX); it requires two things:

  1. that hello.py has proper rights (execute bit set)
  2. that the first line of hello.py is #!/usr/bin/python (or similar, depending on location of your Python interpreter)

The other form - python hello.py - does not have such requirements.

Upvotes: 5

Related Questions