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.

2
  • This seems like a better fit for stackoverflow. Commented Jul 21, 2015 at 14:45
  • Put #!/usr/bin/env python in the first line?
    – yaegashi
    Commented Jul 21, 2015 at 14:45

1 Answer 1

6

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
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .