running IDLE from another program?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Salerno

    running IDLE from another program?

    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?
  • Kent Johnson

    #2
    Re: running IDLE from another program?

    John Salerno wrote:[color=blue]
    > 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.[/color]

    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

    Comment

    • markscala@gmail.com

      #3
      Re: running IDLE from another program?

      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.

      Comment

      • John Salerno

        #4
        Re: running IDLE from another program?

        Kent Johnson wrote:[color=blue]
        > John Salerno wrote:[color=green]
        >> 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.[/color]
        >
        > 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[/color]

        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\pyt hon.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.

        Comment

        • BartlebyScrivener

          #5
          Re: running IDLE from another program?

          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

          Comment

          • Kent Johnson

            #6
            Re: running IDLE from another program?

            John Salerno wrote:[color=blue]
            > Kent Johnson wrote:[color=green]
            >>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.
            >>[/color]
            > 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\pyt hon.exe module ?[/color]

            C:\Python24\pyt hon.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...


            Kent

            Comment

            • John Salerno

              #7
              Re: running IDLE from another program?

              Kent Johnson wrote:[color=blue]
              > John Salerno wrote:[color=green]
              >> Kent Johnson wrote:[color=darkred]
              >>> 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.
              >>>[/color]
              >> 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\pyt hon.exe module ?[/color]
              >
              > C:\Python24\pyt hon.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[/color]

              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\my scripts\challen ge\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.

              Comment

              • Kent Johnson

                #8
                Re: running IDLE from another program?

                John Salerno wrote:[color=blue]
                > Kent Johnson wrote:
                >[color=green]
                >>John Salerno wrote:
                >>[color=darkred]
                >>>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 ?[/color]
                >>
                >>C:\Python24\p ython.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[/color]
                >
                >
                > 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.[/color]

                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.[color=blue]
                >
                > 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\my scripts\challen ge\small_letter .py", line 15, in ?
                > raw_input()
                > EOFError: EOF when reading a line[/color]

                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.[color=blue]
                >
                >
                > 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.[/color]

                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\mypr og.py

                Kent

                Comment

                • John Salerno

                  #9
                  Re: running IDLE from another program?

                  Kent Johnson wrote:
                  [color=blue]
                  > 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.[/color]

                  No, just an environment like IDLE that shows errors instead of just
                  killing the program.
                  [color=blue]
                  > 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.[/color]

                  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.
                  [color=blue]
                  > 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.[/color]

                  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?
                  [color=blue]
                  > 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\mypr og.py[/color]

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

                  Comment

                  • Kent Johnson

                    #10
                    Re: running IDLE from another program?

                    John Salerno wrote:[color=blue]
                    > Kent Johnson wrote:[color=green]
                    >>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.[/color]
                    >
                    >
                    > 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?[/color]

                    mmm, both. TextPad lets me set a regular expression to interpret errors
                    as file/line. When that is set correctly the double-clicking works.[color=blue]
                    >[color=green]
                    >>Try
                    >>C:\Python24\L ib\idlelib\idle -r C:\path\to\mypr og.py[/color]
                    >
                    >
                    > I tried this but it said it couldn't find idle.pyw (even though it is
                    > there).[/color]

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

                    C:\Python24\pyt honw C:\Python24\Lib \idlelib\idle.p yw -r C:\path\to\mypr og.py

                    Kent

                    Comment

                    • John Salerno

                      #11
                      Re: running IDLE from another program?

                      Kent Johnson wrote:
                      [color=blue]
                      > The working directory must be wrong. Try calling Python directly with
                      > full paths:
                      >
                      > C:\Python24\pyt honw C:\Python24\Lib \idlelib\idle.p yw -r C:\path\to\mypr og.py[/color]

                      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!

                      Comment

                      • Kent Johnson

                        #12
                        Re: running IDLE from another program?

                        John Salerno wrote:[color=blue]
                        > Kent Johnson wrote:
                        >[color=green]
                        >>The working directory must be wrong. Try calling Python directly with
                        >>full paths:
                        >>
                        >>C:\Python24\p ythonw C:\Python24\Lib \idlelib\idle.p yw -r C:\path\to\mypr og.py[/color]
                        >
                        >
                        > 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.[/color]

                        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

                        Comment

                        • John Salerno

                          #13
                          Re: running IDLE from another program?

                          Kent Johnson wrote:[color=blue]
                          > John Salerno wrote:[color=green]
                          >> Kent Johnson wrote:
                          >>[color=darkred]
                          >>> The working directory must be wrong. Try calling Python directly with
                          >>> full paths:
                          >>>
                          >>> C:\Python24\pyt honw C:\Python24\Lib \idlelib\idle.p yw -r C:\path\to\mypr og.py[/color]
                          >>
                          >> 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.[/color]
                          >
                          > 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[/color]

                          Ok, thanks again! I love how this works now! :)

                          Comment

                          • jussij@zeusedit.com

                            #14
                            Re: running IDLE from another program?

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

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



                            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).

                            Comment

                            Working...