-3

I try use the super admin and use #!/usr/bin/python at the top however it also doesn't work

Actually, I want to open the .py document but terminal shows that print: command not found.

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
Jeremy
  • 1
  • 1
  • 1
    You type python code directly into your shell... What you want is to create a new text file, add your python code in there and then just run it from shell via `python thefile.py` or `./thefile.py` (if `+x` is set). – jbndlr Mar 12 '16 at 13:49
  • 1
    Firstly, **show the text output here**, don't link to a picture of code. Secondly, in neither of those cases have you actually started the Python shell. – Daniel Roseman Mar 12 '16 at 13:49
  • You don't need to copy and paste the #! characters. If you run /usr/bin/python (or probably just python) you will get a python session. Right now you are still in bash. – Oli Mar 12 '16 at 13:51
  • You put the `#!` (shebang) at the top of files, but you don't need it in an interactive shell. Your problem is that you are still in bash, not in python. Try typing `python` before doing anything else. – zondo Mar 12 '16 at 14:10
  • sorry,My question is not clear,in fact I make a stupid mistake but all you help me to know that.Thank you all! – Jeremy Mar 12 '16 at 15:39

1 Answers1

3

Just type python in your terminal to invoke the interactive shell. You gave the command in the bash terminal beginning with #, which inactivated the whole line.

If you want to run a python script, then put your code in a file like this:

script.py

#!/usr/bin/python

print "2"

Now you can run the code typing python script.py.

The first line of the code is the shebang line, which specifies which interpreter to use, so you can run your script typing ./script.py.

Community
  • 1
  • 1
fodma1
  • 3,485
  • 1
  • 29
  • 49
  • The `#!` is the she-bang line that tells the shell which program to use to interpret the following code. The other `#` signs indicate that the user is in a su shell. Everything's fine with that. – jbndlr Mar 12 '16 at 13:51
  • yes but it doesn't make any sense to use in the terminal – fodma1 Mar 12 '16 at 13:51
  • No doubt. But your answer is still misleading, because uncommentig it (i.e. removing the `#`) will not yield anything functioning. – jbndlr Mar 12 '16 at 13:53
  • but he can start the interactive shell if there's no `#!` in the beginning of the line. My answer is right. – fodma1 Mar 12 '16 at 13:54
  • Did you try starting a program with a `!` in the beginning? Go ahead then. You should probably edit your answer and tell that he has to remove **both** chars to start the interactive shell. You then could elaborate a bit more on the difference between interactive shell and code that is run from a file. – jbndlr Mar 12 '16 at 13:55
  • 1
    No, I said, type __just__ `python` in the shell. And then I explained why it didn't work. – fodma1 Mar 12 '16 at 13:56