#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    1
    Rep Power
    0

    Syntax Error: invalid syntax for a Python newbie.Please help


    I have installed Python 2.5 for Windows and I am trying to run a simple main test. When I try to run it, I am getting the following error.

    Code:
    python main_test.py
    File "<stdin>", line 1
    python main_test.py
                    ^
    Syntax Error : invalid sytax
    My code is as follows:

    Code:
    #/usr/bin/env python  
    """ 
      Test method to run the main method. 
    """  
    
    def main():   
      print "Main method called."
      return;
    
    if __name__ == "__main__":
      main()
    Any help that you give will be very helpful.

    Thanks,
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Location
    EU
    Posts
    63
    Rep Power
    6
    Hi there.

    It looks like you're trying to run the program from within the Python interactive interpreter (the environment that running "python" at a command line produces).

    Try just issuing "python main_test.py" at your command line prompt (i.e. not after you start the interactive interpreter with just "python").

    The Python code itself looks fine, and I get the same error as you posted if I try to issue the command "python main_test.py" within the interactive environment:

    Code:
    >>> python main_test.py
      File "<stdin>", line 1
        python main_test.py
                       ^
    SyntaxError: invalid syntax
    >>>
    Hope that helps. Good luck!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Posts
    20
    Rep Power
    0
    hi krishnan.1000,

    i think u can skip that ; after return as well. it will work in both ways.. still i feel like skipping that ; is more pythonic way
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Posts
    96
    Rep Power
    44
    it seems your coding c/c++ or java for quite sometime... I remember I always had this { } and ; in python
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    USA
    Posts
    334
    Rep Power
    11
    I would also change the first line to directly call the Python interpreter using she-bang syntax.e.
    Code:
    #!/usr/bin/python
    If necessary, change "/usr/bin/python" to wherever your Python interpreter is located.

IMN logo majestic logo threadwatch logo seochat tools logo