syntax error : first python program

Discussion in 'Python' started by pradeep, Dec 23, 2009.

  1. pradeep

    pradeep Guest

    I have this file in linux
    ===============

    sample.py

    #!/usr/bin/env python
    name = "blah"
    print name

    -------------------------------------------

    I executed this

    bash# ./sample.py
    File "./sample.py", line 2
    name = "blah"
    ^
    bash# /usr/bin/python sample.py
    File "sample.py", line 2
    name = "blah"
    ^
    SyntaxError: invalid syntax

    Any one knows , whats the syntax error here?
    pradeep, Dec 23, 2009
    #1
    1. Advertising

  2. pradeep

    Bearophile Guest

    Ben Finney:

    > > bash# /usr/bin/python sample.py
    > >   File "sample.py", line 2
    > >     name = "blah"
    > >     ^
    > > SyntaxError: invalid syntax

    >
    > Indentation is syntax in Python.


    But I agree, a little better error message may help there, something
    that contains "indentation" in it :)

    Bye,
    bearophile
    Bearophile, Dec 23, 2009
    #2
    1. Advertising

  3. pradeep

    Anssi Saari Guest

    Ben Finney <> writes:

    >> bash# /usr/bin/python sample.py
    >> File "sample.py", line 2
    >> name = "blah"
    >> ^
    >> SyntaxError: invalid syntax

    >
    > Indentation is syntax in Python.


    At least here with Python 2.5.2 I get "IndentationError: unexpected
    indent". I'm just wondering why would the OP get a SyntaxError?
    Anssi Saari, Dec 23, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    428
  2. Christopher M. Lusardi
    Replies:
    3
    Views:
    186
    Alan J. Flavell
    Oct 19, 2003
  3. Mark Richards
    Replies:
    3
    Views:
    309
    Tad McClellan
    Nov 18, 2007
  4. Replies:
    27
    Views:
    313
    Chris Angelico
    May 7, 2013
  5. Armando Montes De Oca
    Replies:
    19
    Views:
    264
    Armando Montes De Oca
    Jun 6, 2013
Loading...

Share This Page