469,950 Members | 2,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

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


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?

Sep 25 '08 #1
4 14859
849 Expert 512MB
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.
Sep 25 '08 #2
you can run python program in editor by pressing 'F5' key
Sep 26 '08 #3
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.

Expand|Select|Wrap|Line Numbers
  1. >>> print 2**8
  2. 256
  3. >>> print "test"
  4. 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.

Sep 26 '08 #4
this is a nice solution
Apr 13 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Lee David | last post: by
50 posts views Thread by diffuser78 | last post: by
13 posts views Thread by ago | last post: by
4 posts views Thread by true911m | last post: by
27 posts views Thread by Paulo da Silva | last post: by
3 posts views Thread by corvettecraz92 | last post: by
1 post views Thread by pitjpz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.