FAQ
I'm trying to read some data from standard input, what I'm actually
trying to do is process some date pasted in using the mouse cut and
paste on a Linux box (xubuntu 9.10) in a terminal window.

First attempts failed so I'm now trying the trivial:-

import sys
data = sys.stdin.readlines()
print "Counted", len(data), "lines."


When I run this and try to paste something into the terminal window I
get the following errors:-

/home/chris/bin/m2r.py: line 2: syntax error near unexpected token `('
/home/chris/bin/m2r.py: line 2: `data = sys.stdin.readlines()'


It does exactly the same if I try:-

cat | m2r.py

and then paste something into the window.


So - what on earth am I doing wrong?


--
Chris Green

Search Discussions

  • Richard Thomas at Jan 31, 2010 at 6:26 pm

    On Jan 31, 6:15?pm, tinn... at isbd.co.uk wrote:
    I'm trying to read some data from standard input, what I'm actually
    trying to do is process some date pasted in using the mouse cut and
    paste on a Linux box (xubuntu 9.10) in a terminal window.

    First attempts failed so I'm now trying the trivial:-

    ? ? import sys
    ? ? data = sys.stdin.readlines()
    ? ? print "Counted", len(data), "lines."

    When I run this and try to paste something into the terminal window I
    get the following errors:-

    ? ? /home/chris/bin/m2r.py: line 2: syntax error near unexpected token `('
    ? ? /home/chris/bin/m2r.py: line 2: `data = sys.stdin.readlines()'

    It does exactly the same if I try:-

    ? ? cat | m2r.py

    and then paste something into the window.

    So - what on earth am I doing wrong?

    --
    Chris Green
    You haven't put a shebang line at the top.

    #!/usr/bin/env python
    import sys
    data = sys.stdin.readlines()
    ...
  • Tinnews at Jan 31, 2010 at 10:24 pm

    Richard Thomas wrote:
    On Jan 31, 6:15?pm, tinn... at isbd.co.uk wrote:
    I'm trying to read some data from standard input, what I'm actually
    trying to do is process some date pasted in using the mouse cut and
    paste on a Linux box (xubuntu 9.10) in a terminal window.

    First attempts failed so I'm now trying the trivial:-

    ? ? import sys
    ? ? data = sys.stdin.readlines()
    ? ? print "Counted", len(data), "lines."

    When I run this and try to paste something into the terminal window I
    get the following errors:-

    ? ? /home/chris/bin/m2r.py: line 2: syntax error near unexpected token `('
    ? ? /home/chris/bin/m2r.py: line 2: `data = sys.stdin.readlines()'

    It does exactly the same if I try:-

    ? ? cat | m2r.py

    and then paste something into the window.

    So - what on earth am I doing wrong?

    --
    Chris Green
    You haven't put a shebang line at the top.

    #!/usr/bin/env python
    import sys
    data = sys.stdin.readlines()
    ...
    Urk!!! Silly me. That catches me out every few months! :-)

    --
    Chris Green
  • Steve Holden at Jan 31, 2010 at 6:36 pm

    tinnews at isbd.co.uk wrote:
    I'm trying to read some data from standard input, what I'm actually
    trying to do is process some date pasted in using the mouse cut and
    paste on a Linux box (xubuntu 9.10) in a terminal window.

    First attempts failed so I'm now trying the trivial:-

    import sys
    data = sys.stdin.readlines()
    print "Counted", len(data), "lines."


    When I run this and try to paste something into the terminal window I
    get the following errors:-

    /home/chris/bin/m2r.py: line 2: syntax error near unexpected token `('
    /home/chris/bin/m2r.py: line 2: `data = sys.stdin.readlines()'


    It does exactly the same if I try:-

    cat | m2r.py

    and then paste something into the window.


    So - what on earth am I doing wrong?
    Trying to run Python scripts with /bin/sh, probably.

    First of all, does you PATH include the current directory (.)? It looks
    like it does, because your computer seems to be trying to execute the
    m2r.py script. However, because that script does not start with a
    "shebang" line - the one you need is probably either

    #!/usr/bin/python

    or

    #!/usr/bin/env python

    the shell is trying to run the script using the wrong interpreter.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
    Holden Web LLC http://www.holdenweb.com/
    UPCOMING EVENTS: http://holdenweb.eventbrite.com/
  • Grant Edwards at Jan 31, 2010 at 6:50 pm

    On 2010-01-31, Steve Holden wrote:
    tinnews at isbd.co.uk wrote:
    I'm trying to read some data from standard input, what I'm actually
    trying to do is process some date pasted in using the mouse cut and
    paste on a Linux box (xubuntu 9.10) in a terminal window.

    First attempts failed so I'm now trying the trivial:-

    import sys
    data = sys.stdin.readlines()
    print "Counted", len(data), "lines."


    When I run this and try to paste something into the terminal window I
    get the following errors:-

    /home/chris/bin/m2r.py: line 2: syntax error near unexpected token `('
    /home/chris/bin/m2r.py: line 2: `data = sys.stdin.readlines()'


    It does exactly the same if I try:-

    cat | m2r.py

    and then paste something into the window.


    So - what on earth am I doing wrong?
    Trying to run Python scripts with /bin/sh, probably.
    Yup. I can't count the number of times I've run ImageMagick's
    "import" program unintentionally...

    --
    Grant Edwards grante Yow! The SAME WAVE keeps
    at coming in and COLLAPSING
    visi.com like a rayon MUU-MUU ...

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJan 31, '10 at 6:15p
activeJan 31, '10 at 10:24p
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase