Tapatalk

Setting up UE to run the Python interpreter?

Setting up UE to run the Python interpreter?

601
Advanced UserAdvanced User
601

    Mar 15, 2006#1

    Is there a way to set up UE so that I can execute the Python code I've written in it, possibly through IDLE or some other interactive interpreter of that sort?

    I'm sure this is possible, but I don't know how to set it up beyond creating the basic link to the program itself. I don't know how to get my code to actually run in the external program.

    Thanks,
    John

    344
    MasterMaster
    344

      Mar 15, 2006#2

      Hi John,

      I don't know anything about Python, but if you can call your Python from the prompt with the file as parameter, you can easily setup a tool in UE.

      E.g.: idlepythonwhatever.exe "%f"

      So, %f is the substitution for your file you are working on.

      rds Bego

      601
      Advanced UserAdvanced User
      601

        Mar 15, 2006#3

        Thanks, I'll give that a try.

        Edit: Now that I think about it, I'm not sure this will work. This might work for the DOS command prompt, because to run a program that way, the command would be python filename.ext. (Although I don't know how I'd get the word 'python' in there).

        But I'm trying to run the code within a more specific environment, and the way to do it there would be to run import filename (without the extension). Is it possible to configure the tool to input this information in the program once it opens?

        344
        MasterMaster
        344

          Mar 16, 2006#4

          I just tried to do a "%f" in the tools dialog with a test.vbs script
          AND IT WORKED, so without a wscript.exe "%f"

          --> if a double click in Windows Explorer on your Python files start your script correctly, a "%f" is all you need :-)

          Use Windows Explorer, Tools, File Types to associate extensions to applications.

          rds Bego

          601
          Advanced UserAdvanced User
          601

            Mar 16, 2006#5

            Thanks again! I'll do some testing when I get home. :)

              Mar 16, 2006#6

              Well, I'm not having much luck. I tried a few things, but nothing seems to happen. But I've narrowed down exactly what I want, so maybe this will help: instead of trying to load the current file into some other application, all I really need to do is run it just as if I had double clicked on it. I tried using just "%f", but that didn't do anything.

              344
              MasterMaster
              344

                Mar 16, 2006#7

                Hmmm ....

                - If you double click on the file from Explorer, does it start then?
                - You are working on a SAVED file, don't you?
                - You are working on a local Windows file, NOT working on a FTP file?

                If you got three "Yes" here, I don't have any more ideas why it doesn't work.

                rds Bego

                601
                Advanced UserAdvanced User
                601

                  Mar 16, 2006#8

                  Yes for the first two, not sure about the third because it's actually a DOS window that gets run, not a regular Windows program. Not sure if that affects anything, but I've tried checking and unchecking the option of a Windows program in the Tools Configuration, and neither worked.

                  I've tried putting %f, %F, "%f" and "%F" in the command line, and I've also tried it with the command path of the python program itself, but nothing works.

                  I have noticed, however, that after running the tool, python.exe is a running process in my task manager, so perhaps it is somehow running it, but for whatever reason I don't see anything on the screen.

                  119
                  Power UserPower User
                  119

                    Mar 17, 2006#9

                    Try this, where "*" and "x" indicate radio and check box selections.

                    Code: Select all

                    Command line: python "%f"
                    Working Directory: %P
                    Menu Item Name: Run Python Script
                    [ ] Windows Program
                    [ ] Save all files first
                    [x] Save Active File
                    ( ) Append to Existing
                    (*) Replace Existing
                    ( ) Create New File
                    ( ) Output to List Box
                    [x] Show DOS Box
                    [x] Capture Output
                    If Python isn't in your path, provide the full path on the command line.

                    601
                    Advanced UserAdvanced User
                    601

                      Mar 17, 2006#10

                      Thanks! I think it was the Show DOS Box option that was tripping me up. Even if I put just "%f" in the command line, and nothing in the working directory, it still works now.

                      Thanks again!  :)

                      119
                      Power UserPower User
                      119

                        Mar 17, 2006#11

                        JohnJSal wrote:Even if I put [...] nothing in the working directory, it still works now.
                        The working directory sets the enviroment for the running program. So if (e.g.) you want to open a file in the same directory as the script, you should set it.

                        601
                        Advanced UserAdvanced User
                        601

                          Mar 17, 2006#12

                          Yeah, I did set it, after all. But I had to use %P, because "%p" gave me an error for some reason.

                          Edit: The working directory must be always set without double quotes even if directory path contains spaces or when using %p (long path) instead of %P (short 8.3 path always with no spaces).