7

I'm trying to figure out how to successfully use Python 2.7.1 on windows 7.
So far, I'm having to use the shell (IDLE) to create scripts and then run them from the cmd prompt. I feel this is slowing down the learning process and I was wondering if there was a way to run it from IDLE (I'm not able to create a pathway, so whenever i try to open or import a file i get an error) or some other program/text editor perhaps?

Any help would be appreciated! I'm probably just doing something wrong.

5
  • IDLE certainly allows to run a script from the editor; what error do you get? Commented Jun 28, 2011 at 22:51
  • This question basically tells me nothing about what the actual problem is. Also, what's a "pathway"? Commented Jun 28, 2011 at 22:54
  • Once you have your script open, just hit F5 (or go to Run->Run Module) to run it. It's as simple as that. Commented Jun 28, 2011 at 23:11
  • @Dontcare4free, the problem is what i mentioned below, i didn't know how to describe it. Commented Jun 28, 2011 at 23:48
  • use gist to post your script there. I suspect an error in your code Commented Jun 29, 2011 at 1:19

2 Answers 2

20
  1. Run IDLE. You will be presented with the "Python Shell" window and a >>> prompt.
  2. Click File, New Window. You will be presented with an "Untitled" window for editing a script.
  3. Enter your script in the "Untitled" window.
  4. In the "Untitled" window, select Run, Run Module (or press F5) to run your script.
  5. A dialog "Source Must Be Saved. OK to Save?" appears. Click OK.
  6. In the Save As dialog:
    a. Browse to a directory to save your script.
    b. Enter a filename.
    c. Click Save.
  7. The "Python Shell" window will display the output of your script.
  8. Edit script and press F5 as needed to re-run your script.

Edit

I don't normally use IDLE, and didn't immediately see a way to configure parameters to the module, so one suggestion is to switch IDEs. Since you are using Windows 7, the pywin32 extensions contains the PythonWin IDE and its Run command has a dialog to allow command line parameters to be entered.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, this i already know. I explained it horribly, because honestly i have no idea what i'm talking about or how to go about it. I just started learning and it's been self taught. I'm trying to practice using "raw_input" and if i want to run a file, it says this: "Traceback (most recent call last): File "C:users\username\Desktop\python\expert.py", line 4, in <module> script, filename= argv ValueError: need more than 1 value to unpack" how am i supposed to run a file if i can't put a value?
Try filename = raw_input('Enter filename? ').
5

I think you have in mind the following function:

execfile(...)

execfile(filename[, globals[, locals]])

Read and execute a Python script from a file.
The globals and locals are dictionaries, defaulting to the current
globals and locals.  If only globals is given, locals defaults to it.

Note:

This only applies to python 2.x, python 3 does not have execfile(), instead see What is an alternative to execfile in Python 3?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.