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

3

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
  • 198,278
  • 20
  • 158
  • 249
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
  • 28,963
  • 9
  • 62
  • 81