6

I could add #! /usr/bin/python in the beginning of python script and add this script to PATH in order to run it as a command.

But could anyone explain to me what does '#' and '!' mean separately in python and what other language has this mechanism? Thanks

2 Answers2

2

This is the shebang line and the #! are magic numbers interpreted by the program loader on unix systems and used to start the script interpreter.

Elliott Frisch
  • 183,598
  • 16
  • 131
  • 226
1

# followed by anything is a comment; so far as Python itself is concerned, that's it. Unix, on the other hand, will parse out the /usr/bin/python so that it knows how to run your code.

Kevin
  • 25,251
  • 7
  • 54
  • 78