Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
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
up vote 5 down vote accepted

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
share|improve this answer
    
Thanks, that worked perfectly. – Charles Stapleford Jul 21 '15 at 14:51
    
@CharlesStapleford, don't forget to accept this answer: unix.stackexchange.com/help/someone-answers – glenn jackman Jul 21 '15 at 15:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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