0

I'm trying to use python to read in data from a text file but I keep getting "syntax" errors when I execute the program.

Python Code: Test.py

import os
import numpy as np

Ye,Eb,Tb = np.genfromtxt("ye_tnuebar_table.txt",unpack=True)
print Ye
print Tb

Note: I've also used the np.loadtxt function with the same result.

Once I save my program, I go to my bash shell and run it with:

./Test.py

After about a minute and a half I get back the following errors:

./Test.py: line 6: syntax error near unexpected token `('
./Test.py: line 6: `Ye,Eb,Tb = np.genfromtxt("ye_tnuebar_table.txt", unpack=True)'

I've looked up documentation on the loadtxt and genfromtxt functions and everything I've seen says that the python is correct, so I have no idea what is going wrong or how to fix it.

  • This seems like a better fit for stackoverflow. – user1794469 Jul 21 '15 at 14:45
  • Put #!/usr/bin/env python in the first line? – yaegashi Jul 21 '15 at 14:45
5

The shell doesn't know it's a python program, so it's trying to execute the commands as shell commands: you either need to tell it to use the python interpreter explicitly on the command line

python Test.py

or add a shebang to the top of your script file

#!/usr/bin/env python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.