starting Python IDLE from command line to edit scripts
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 throwing any errors.
开发者_高级运维So how can I do the equivalent of opening IDLE, file>open>filepath via the command line (or perhaps even a Python module)?
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
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.
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.
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).
first make sure you have location of idle in path
I am using "python3.5".So mine looks like this:
C:\Program Files\Python35\Lib\idlelib
.Yours may differ.
use this following command:idle -r file_name.py
to run the file
or just idle file_name.py
to edit
or
start idle -r file_name.py ^&exit
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.
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!
paste the idlelib to your system path or user path, environment variable.for example, like this C:\Program Files\Python310\Lib\idlelib
then type idle in your command prompt. done.
精彩评论