Newbie Question:Please help

Steve Holden steve at holdenweb.com
Fri Sep 12 18:34:10 CEST 2008


Karthik Krishnan wrote:
> Hi,
> 
> I am a newbie to python and I hope this is not a stupid question. I am
> trying to run a main method from a Python command line using the command
> shell using the command.
> 
> python main_test.py
> 
> I get the following error.
> 
> 
> File "<stdin>", line 1
>   python main_test.py
> 
> Syntax Error: invalid syntax
> 
> My main file main_test.py is given below.
> 
> #!/usr/bin/env python
> 
> """ Test method to run the main method.
> 
> """
> 
> def main():
>   print "Main method called.";
> 
> 
> if __name__ = "__main__":
>   main()
> 
Apart from the syntax error Rob pointed out (use of "=" instead of "=="
as a comparison operator) the output you show makes it seem possible you
are entering the command "python main_test.py" at the Python interpreter
interactive prompt ">>>". That won't work, as you are supposed to enter
Python statements and expressions there.

"python" is an operating system command, so you want to enter "python
main_test.py" in a command window (terminal window, shell window, call
it what you will). I'm guessing (possibly incorrectly) that you are a
Windows user, and got your interactive Python window by choosing "Python
(command line)" from the Start | Programs menu.

See the FAQ for further information, possibly

  http://www.python.org/doc/faq/windows/

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list