473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

1
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!
Sep 25 '08 #1
4 14990
Laharl
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
aberry
10
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
  5.  
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
Sep 26 '08 #4
@aberry
this is a nice solution
Apr 13 '12 #5

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

Similar topics

5
by: Lee David | last post by:
I went to the sun site and downloaded what I hope is the development part of java. I downloaded JDK5 with Netbeans. I installed it and now have a folder in my program group "Netbeans". Is that...
50
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
13
by: ago | last post by:
I have just discovered Python Scripter by Kiriakos Vlahos and it was a pleasant surprise. I thought that it deserved to be signalled. It is slim and fairly fast, with embedded graphical debugger,...
10
true911m
by: true911m | last post by:
This is a simple walkthrough to get PyInstaller up and running. I decided to give PI a try, because it claims to be more selective about what it bundles into its executable files by default, and...
4
true911m
by: true911m | last post by:
Here's a little walkthrough to get py2exe up and running. I'm not an expert, so I can't help much with any problems you might have. This is what worked for me. The result here will be to convert...
27
by: Paulo da Silva | last post by:
Hi! I was told in this NG that string is obsolet. I should use str methods. So, how do I join a list of strings delimited by a given char, let's say ','? Old way:
4
by: maria | last post by:
I only use C++ with Visual Studio 6.0 for string manipulations in thousands of HTML pages on my website. Many times, the output files of many of my C++ programs contain a spanish question mark (¿)...
3
by: corvettecraz92 | last post by:
I want to create a program where a user can type what ever they want to, have it saved to a file, and the be able to re-open it and read it. How would I do this? Thanks!
1
by: pitjpz | last post by:
We have moved our Database to another server. The server it was on used SQL 4 and the new one its on now uses SQL5 the only problem we can find is that when you attempt to delete a record from...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.