starting Python IDLE from command line to edit scripts

后端 未结 7 1716
北荒
北荒 2021-01-12 02:25

I\'ve tried many variations of this command: idle.py -e filepath, but it simply starts IDLE like normal, not opening any extra windows for editing, and not thro

相关标签:
7条回答
  • 2021-01-12 02:39

    Please forgive me for bumping such an old thread, but I've been teaching myself linux and python with the help of the community, and was trying to figure out how to invoke IDLE2 and IDLE3 from the command line. I came across this post some of the solutions seemed a bit complicated for my application. Then it occurred to me that I could just put syslinks in the /usr/bin/ path for each.

    sudo ln -s idle-python3.1 idle3
    sudo ln -s idle-python2.6 idle2
    

    to address the OP. From the directory the script is located, type:

    idle3 abc123.py 
    

    or

    idle2 abc123.py
    

    I'm just so damned happy that I finally had a "light bulb" go off that I wasn't going to let a 2 year old post stop me from posting my solution.

    0 讨论(0)
  • 2021-01-12 02:46

    You need to do as stated in the main.py file of the idelib folder (C:\Python33\Lib\idlelib), at least on the python 3.3 version explains that:

    IDLE main entry point
    
    Run IDLE as python -m idlelib
    

    So with python -m idlelib <script_to_edit> you will be able to open and edit the script with idle. I haven't checked with previous versions but it could be the same comand

    This is also documented on the changelog of the version 3.3.3

    0 讨论(0)
  • 2021-01-12 02:48

    you can just program in Python to edit your Python files. A simple example. say you want to search for a word and then replace it with something else.

    import fileinput
    import os
    os.chdir( os.path.join("c:\\","path") )
    for file in os.listdir("."):
        for line in fileinput.input(file,inplace=0):
           if "search word" in line :
               line=line.replace("search word","new word")
               print line
    

    (use inplace=1 to do in place editing.). Then save and run the script as normal Python script using the interpreter.

    0 讨论(0)
  • 2021-01-12 02:50

    Make a new text file, and put something like this in it:

    C:\Python26\Lib\idlelib\idle.pyw "C:\file1.py" "C:\file2.py"
    

    In your actual script, you'll replace "C:\file1.py" and "C:\file2.py" with your files' paths, save as a .bat, and then launch it. That should do what you want.

    0 讨论(0)
  • 2021-01-12 02:58

    Rarely the native os is useful. I created a 'win batch file, in the folder with my .py files:

    start /MIN cmd /C c:\Python27\lib\idlelib\idle.py -e %1 %2 %3 %4 %5 %6
    

    This can open up to six files from cmd line in one shot. Just type the name of the batch file, followed by from zero to six filenames. Also if one or more files you specify are not found, idle opens these as new document(s).

    0 讨论(0)
  • 2021-01-12 02:58

    Just add IDLE's path to your PATH environment variable.

    For example I created an environment variable called IDLE_PATH and set the value to C:\Python27\Lib\idlelib

    Then in my PATH variable I added ;%IDLE_PATH%; and open a new cmd prompt or in console2 just open a new tab and run idle <file_name> to open the file, you will be able to do this from any directory. In IPython console add an ! before the command, for example !idle test.py.

    Congrates, Now you're a python pimp!

    0 讨论(0)
提交回复
热议问题