Very simple question: how to run .py file using a Python editor in Windows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cosmid
    New Member
    • Sep 2008
    • 1

    Very simple question: how to run .py file using a Python editor in Windows

    Hi,

    I am new to Python. Just started learning it. I am just trying to follow the book and run the example given in the book. I created a module by saving 2 python statements in notepad and saved the file in .py format just like the book said. the two statements are:
    print 2**8
    print 'test'

    I saved the file as test.py. The book's example given is using shell. I am using the Python installed for Windows. I also checked the tutorials for Windows. I tried the following and none of them worked:
    >>>python test.py
    >>>C:\Python25> python test.py

    the error message for both:
    SyntaxError: Invalid syntax

    For python test.py the word is high lighted in red with the error message. and for the C:\ the : is high lighted in red with the error message.

    I also tried setting the path in dos using set path=%path%;c:\ python25

    My question is, how do I run the script using the Python editor in Windows?

    Thanks!
    Last edited by cosmid; Sep 25 '08, 09:09 PM. Reason: grammar
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    Um...It looks like you've fired up the Python interactive shell. Load up a command prompt (cmd.exe, aka a DOS prompt) instead and then chdir to the folder and type "python test.py" without the quotes. That ought to work, possible pythonpath issues aside.

    Comment

    • aberry
      New Member
      • Sep 2008
      • 10

      #3
      you can run python program in editor by pressing 'F5' key

      Comment

      • freddukes
        New Member
        • Sep 2008
        • 18

        #4
        Make sure you haven't downloaded python 3.0 beta as it has turned the "print" statement into a function rather than an embedded engine call... As other people have states as well, it seems you have run python interactive shell... This is just a shell which directly executes python commands without the need of saving them... e.g.

        Code:
        >>> print 2**8
        256
        >>> print "test"
        test
        As you see it does the code directly. No need for saving files and loading them via command prompt. IDLE is BRILLIANT for testing code that you're unsure about. It is one of the best testing environment I've ever seen for any programming language.

        -freddukes

        Comment

        • planruk
          New Member
          • Apr 2012
          • 1

          #5
          thank you

          Originally posted by aberry
          you can run python program in editor by pressing 'F5' key
          this is a nice solution

          Comment

          Working...