By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,876 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,876 IT Pros & Developers. It's quick & easy.

running IDLE from another program?

P: n/a
If I want to write my code in a separate text editor (I like UltraEdit)
but then press a single button to have that code run in the IDLE
environment, is that possible? I know that you can configure UE to run
external tools, but I can't figure out how to run IDLE this way, because
when I check on its properties to find it's file path, it is just the
Python directory itself.

So not only do I not know where to find the actual file to run IDLE (if
possible), but I then don't know how to run my code in IDLE (again, if
possible). I guess I could write a script or macro that opens IDLE with
a new code window ready, copies and pastes my code from UE into this
window, then runs that code, but that seems messy, if that would even
work. And wouldn't it also prompt me to save the file before running it
in IDLE anyway?

So it comes down to this: is it possible to run code (that was created
in a separate editor) in IDLE in some kind of automated way?
Mar 31 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
John Salerno wrote:
If I want to write my code in a separate text editor (I like UltraEdit)
but then press a single button to have that code run in the IDLE
environment, is that possible? I know that you can configure UE to run
external tools, but I can't figure out how to run IDLE this way, because
when I check on its properties to find it's file path, it is just the
Python directory itself.


You probably don't need to do that. Just run the file in python
directly. I don't know UE, but when you configure an external tool, tell
it to run python.exe and pass the current file as a command line parameter.

Kent
Mar 31 '06 #2

P: n/a
what i do is open idle, import the codefile i've begun to write, and
then write a function:
def r():
reload(codefile)

then when I want to run it after changes, I just call the function
manually in idle.

Mar 31 '06 #3

P: n/a
Kent Johnson wrote:
John Salerno wrote:
If I want to write my code in a separate text editor (I like UltraEdit)
but then press a single button to have that code run in the IDLE
environment, is that possible? I know that you can configure UE to run
external tools, but I can't figure out how to run IDLE this way, because
when I check on its properties to find it's file path, it is just the
Python directory itself.


You probably don't need to do that. Just run the file in python
directly. I don't know UE, but when you configure an external tool, tell
it to run python.exe and pass the current file as a command line parameter.

Kent


I've tried a lot of combinations for the command line to execute, but
nothing is working. What format should it be in? Should it look like this:

C:\Python24\python.exe module ?

or module.ext? With or without the path of the file?

I think some of the problem might be that I need to fix the module
search path also, but I don't know which format the UE tool needs to
execute the command.
Mar 31 '06 #4

P: n/a
John,

If your file has the .py or .pyc extension on it, it should just run at
the command line from its own directory, assuming your environment and
path variables are set correctly.

I use NoteTab which has a different way of doing it, but basically you
should be able to run:

c:\mydir>script.py

You don't need the python.exe on the commandline.

rick

Apr 1 '06 #5

P: n/a
John Salerno wrote:
Kent Johnson wrote:
You probably don't need to do that. Just run the file in python
directly. I don't know UE, but when you configure an external tool, tell
it to run python.exe and pass the current file as a command line parameter.

I've tried a lot of combinations for the command line to execute, but
nothing is working. What format should it be in? Should it look like this:

C:\Python24\python.exe module ?


C:\Python24\python.exe D:\full\path\to\myprogram.py

There is a post on the UltraEdit forum from JohnJSal, is that not you?
Whoever it is got this working...
http://www.ultraedit.com/index.php?n...ghlight=python

Kent
Apr 1 '06 #6

P: n/a
Kent Johnson wrote:
John Salerno wrote:
Kent Johnson wrote:
You probably don't need to do that. Just run the file in python
directly. I don't know UE, but when you configure an external tool, tell
it to run python.exe and pass the current file as a command line parameter.

I've tried a lot of combinations for the command line to execute, but
nothing is working. What format should it be in? Should it look like this:

C:\Python24\python.exe module ?


C:\Python24\python.exe D:\full\path\to\myprogram.py

There is a post on the UltraEdit forum from JohnJSal, is that not you?
Whoever it is got this working...
http://www.ultraedit.com/index.php?n...ghlight=python

Kent


Yes, that's me. :) But all that that post accomplished was getting me to
run the file itself, as if I had double-clicked on it. This isn't what I
want. I want it to run in a 'debug' type of environment like IDLE so I
can see any error messages.

I tried your suggestion and seems to half-way work. But it doesn't open
the program in a different environment (such as IDLE), it just opens the
output in a new text window in UE. Here's the output:

['qIQNlQSLi', 'eOEKiVEYj', 'aZADnMCZq', 'bZUTkLYNg', 'uCNDeHSBj',
'kOIXdKBFh', 'dXJVlGZVm', 'gZAGiLQZx', 'vCJAsACFl', 'qKWGtIDCj']
Traceback (most recent call last):
File "C:\Python24\myscripts\challenge\small_letter. py", line 15, in ?
raw_input()
EOFError: EOF when reading a line
The list is the output from the script. I don't know why the end of file
error is raised though, because it wouldn't have been raised if I ran
the file in IDLE. So something still isn't quite right.
Apr 1 '06 #7

P: n/a
John Salerno wrote:
Kent Johnson wrote:
John Salerno wrote:
Kent Johnson wrote:

You probably don't need to do that. Just run the file in python
directly. I don't know UE, but when you configure an external tool, tell
it to run python.exe and pass the current file as a command line parameter.
I've tried a lot of combinations for the command line to execute, but
nothing is working. What format should it be in? Should it look like this:

C:\Python24\python.exe module ?
C:\Python24\python.exe D:\full\path\to\myprogram.py

There is a post on the UltraEdit forum from JohnJSal, is that not you?
Whoever it is got this working...
http://www.ultraedit.com/index.php?n...ghlight=python

Kent

Yes, that's me. :) But all that that post accomplished was getting me to
run the file itself, as if I had double-clicked on it. This isn't what I
want. I want it to run in a 'debug' type of environment like IDLE so I
can see any error messages.


I'm not sure what you mean by a 'debug' type environment. If you mean,
you want to run the program in a debugger and step through it, then this
approach won't work. If you just mean that you want to see the output of
the program, it will work.
I tried your suggestion and seems to half-way work. But it doesn't open
the program in a different environment (such as IDLE), it just opens the
output in a new text window in UE. Here's the output:

['qIQNlQSLi', 'eOEKiVEYj', 'aZADnMCZq', 'bZUTkLYNg', 'uCNDeHSBj',
'kOIXdKBFh', 'dXJVlGZVm', 'gZAGiLQZx', 'vCJAsACFl', 'qKWGtIDCj']
Traceback (most recent call last):
File "C:\Python24\myscripts\challenge\small_letter. py", line 15, in ?
raw_input()
EOFError: EOF when reading a line
OK, your program is reading from standard input and the environment set
up by UltraEdit doesn't support this. If you are trying to run
interactive programs this approach won't work.

The list is the output from the script. I don't know why the end of file
error is raised though, because it wouldn't have been raised if I ran
the file in IDLE. So something still isn't quite right.


Because IDLE does support input.

I may have put too much interpretation on your original question because
I have my editor (TextPad) configured to run the front window in Python
and I find it a very productive way to work. But it's not IDLE and it
doesn't allow interactive input. I rarely write a program that requires
keyboard input so that's not a problem for me.

One thing that is really useful about running in an editor window is
that (in TextPad, anyway) I can double-click on an error message and go
directly to the line with the error.

Anyway, it turns out IDLE has a command-line switch that lets you pass a
file to run. Try
C:\Python24\Lib\idlelib\idle -r C:\path\to\myprog.py

Kent
Apr 1 '06 #8

P: n/a
Kent Johnson wrote:
I'm not sure what you mean by a 'debug' type environment. If you mean,
you want to run the program in a debugger and step through it, then this
approach won't work. If you just mean that you want to see the output of
the program, it will work.
No, just an environment like IDLE that shows errors instead of just
killing the program.
OK, your program is reading from standard input and the environment set
up by UltraEdit doesn't support this. If you are trying to run
interactive programs this approach won't work.
Oh, I see! I had the raw_input() in there so it would pause the DOS
prompt for me, but after taking out that line, then it works how I want
it to.
One thing that is really useful about running in an editor window is
that (in TextPad, anyway) I can double-click on an error message and go
directly to the line with the error.
Interesting. The way I have it now, it shows errors the way I want to,
but it shows them just in a text file, nothing special, and I don't seem
to be able to double-click them. Is this just a feature of TextPad, or
did you have to set it up so you can double-click the errors?
Anyway, it turns out IDLE has a command-line switch that lets you pass a
file to run. Try
C:\Python24\Lib\idlelib\idle -r C:\path\to\myprog.py


I tried this but it said it couldn't find idle.pyw (even though it is
there).
Apr 1 '06 #9

P: n/a
John Salerno wrote:
Kent Johnson wrote:
One thing that is really useful about running in an editor window is
that (in TextPad, anyway) I can double-click on an error message and go
directly to the line with the error.

Interesting. The way I have it now, it shows errors the way I want to,
but it shows them just in a text file, nothing special, and I don't seem
to be able to double-click them. Is this just a feature of TextPad, or
did you have to set it up so you can double-click the errors?


mmm, both. TextPad lets me set a regular expression to interpret errors
as file/line. When that is set correctly the double-clicking works.
Try
C:\Python24\Lib\idlelib\idle -r C:\path\to\myprog.py

I tried this but it said it couldn't find idle.pyw (even though it is
there).


The working directory must be wrong. Try calling Python directly with
full paths:

C:\Python24\pythonw C:\Python24\Lib\idlelib\idle.pyw -r C:\path\to\myprog.py

Kent
Apr 1 '06 #10

P: n/a
Kent Johnson wrote:
The working directory must be wrong. Try calling Python directly with
full paths:

C:\Python24\pythonw C:\Python24\Lib\idlelib\idle.pyw -r C:\path\to\myprog.py


Perfect! Thank you so much!

I put this line in the command line field, and I left "working
directory" empty because I'm not sure what goes there. Should it be the
main python directory, or the directory of the file being run? Either
way, it seems to work without a working directory.

Thanks again!
Apr 1 '06 #11

P: n/a
John Salerno wrote:
Kent Johnson wrote:
The working directory must be wrong. Try calling Python directly with
full paths:

C:\Python24\pythonw C:\Python24\Lib\idlelib\idle.pyw -r C:\path\to\myprog.py

Perfect! Thank you so much!

I put this line in the command line field, and I left "working
directory" empty because I'm not sure what goes there. Should it be the
main python directory, or the directory of the file being run? Either
way, it seems to work without a working directory.


Great! I would set the working directory to the dir containing your
program. That way if you have multiple modules in the program you will
be able to import them without any trouble.

Kent
Apr 2 '06 #12

P: n/a
Kent Johnson wrote:
John Salerno wrote:
Kent Johnson wrote:
The working directory must be wrong. Try calling Python directly with
full paths:

C:\Python24\pythonw C:\Python24\Lib\idlelib\idle.pyw -r C:\path\to\myprog.py


Perfect! Thank you so much!

I put this line in the command line field, and I left "working
directory" empty because I'm not sure what goes there. Should it be the
main python directory, or the directory of the file being run? Either
way, it seems to work without a working directory.


Great! I would set the working directory to the dir containing your
program. That way if you have multiple modules in the program you will
be able to import them without any trouble.

Kent


Ok, thanks again! I love how this works now! :)
Apr 2 '06 #13

P: n/a
> So it comes down to this: is it possible to run code (that
was created in a separate editor) in IDLE in some kind of
automated way?


Using the Zeus for Windows IDE this should be possible. Zeus has
many options when it comes to running tools and compilers:

http://www.zeusedit.com/forum/viewtopic.php?t=32

It will also capture the tool output and allowing you to click
on the errors in the output and have the file load at the correct
line number.

Jussi Jumppanen
Author: Zeus for Windows
Note: Zeus is shareware (45 day trial).

Apr 5 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.