Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (anonymous):

Hi. New to python and programming. Just trying to make this easy to learn. Here is my question: Installed python 3.2.2 on Win 7. Using start menu to fire up python. Get to the interpreter. I coded some simple programs and saved it to a folder on my desktop. Once I start python, how do I run those programs? I do not want to do it each time running win command line and going to that directory. Thanks

OpenStudy (anonymous):

Are you opening a new window or are you typing right into idle? I recommend you save the files after you've opened up a new window. When you save the files make sure you give them a .py extension. You can right click on the program file and choose 'open with Idle".

OpenStudy (anonymous):

Hi Thanks. I think I a bit confused here. I am using python(command line). If I enter all the codes this way, it works. But I saved the code in a Notepad file on my desktop with .py extension. I start python (command line), which is created in start menu at the installation. I can also start python from win command line and go to the directory where the file is and run python filename, but I want to run the file at the >>> prompt when I start the interpreter. hope I am clear

OpenStudy (anonymous):

Just to simplfy: This code below is saved in a folder on my desktop as 123.py. I start python(command line) from windows start menu. How do I run this file? def sqrt(x): """Returns the square root of x, if x is a perfect square. Prints an error message and returns None otherwise""" ans = 0 if x >= 0: while ans*ans < x: ans = ans + 1 if ans*ans != x: print (x, 'is not a perfect square') return None else: return (ans) else: print (x, 'is a negative number') return None

OpenStudy (anonymous):

BluTao, for this course Python3.x will not work, download a 2.x version. Also, in Start Menu, under Python 3.2 or 2.x there should be an option that says IDLE (Python GUI), select that one. That's what most people use. Then go to File -> Open...

OpenStudy (anonymous):

I have 2.7.2 http://www.python.org/getit/

OpenStudy (anonymous):

Carlosgg. Thanks. well..python 3.2 works . It just you have to modify the code a bit. like print needs ()..which is not a big deal to add. So you are saying, use GUI and open the file that way?, but that opens the file just like a text editor. I am still unable to run this way

OpenStudy (anonymous):

@BluTao - I am also using 3.2 and it works just fine, with a few modifications here and there. (like the print() you mentioned and substituting range for xrange, etc.) Anyhow, as to your question, I had the same issue when I first started. I'm not exactly sure if my explanation is technically right, but in practice, it is functionally. The python32 file is a subfolder in C: and when you save your file to your desktop, instead of to that subfolder, your computer isn't "seeing" the program (i.e. python) to use to open it with. You can solve this a few different ways. Change your settings for "open files of this type" to include using python to open .py files. -OR- Move either python to your desktop, or your desktop python files to within the python subfolder. -OR- The method I prefer, I downloaded eclipse and pydev and use that combination instead of IDLE. Then you can simply leave your python32 where it is, and set up workspace documents on your desktop. Then, when you click on any of the files in your workspace folders, they will open directly. Plus, you get all the wonderful benefits of a better IDE. Once you get used to it, IDLE totally sucks in comparison. Anyway, I hope this makes sense, and if not I'll try to explain it better. But I am definitely not a computer guru, so take that into consideration before you change anything based on my advice. Good luck to you with all this! :)

OpenStudy (anonymous):

BluTao, yes it opens in a separate window, then hit F5 or go to the Run menu and select Run Module. pylab (Lecture 18) does not work with Python 3.x, only Python 2.x.

OpenStudy (anonymous):

ok. I just installed 2.7 for the class since it did not want to keep modifying. I can use IDLE and run command as you explained..It works now. at least with IDLE you can do it. I am not sure what is the point of creating python(command line) start menu as it seems to be a lot of configuration needs to be done to get it working if your files are on your desktop or elsewhere. Anyways, thanks all

OpenStudy (anonymous):

That's the way the professors do it during the lectures I think. They also use a 2.x version (2.5.x I think)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!