views:

419

answers:

2

I am working on a project which has about 15 files that I edit often. So in the past, when I start up IDLE, I open those 15 files for editing individually.

I simply wonder if there is a way to automate this, via a .bat file or something. I'm not too good with command line, but I did a bit of research. I came across this page: http://docs.python.org/library/idle.html#command-line-usage. 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)?

+1  A: 

make a new text file, put this on it for example :

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

replace "C:\file1.py" by your files path, save as .bat and launch it, it does what you want

redouane
That doesn't work for me. It has the same results as my example.
Wallacoloo
well, it does work for me.
redouane
Perhaps there is something wrong with my version of IDLE. As a test, I tried `idle -h`, which according PyShell.py should print the help. It only opened the shell though, no output at all. Which version of Python are you using? (2.6 for me (edit: looks like you are too))
Wallacoloo
I found a workaround: `python "C:\Python26\Lib\idlelib\idle.py" "C:\file1.py"` So something with the argument passing simply wasn't working. Not sure what, but hey, it works!
Wallacoloo
A: 

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.

ghostdog74
That would be a very inconvenient way of editing files.
Wallacoloo
why do you think so? you save it as a normal python script, and run it on the command line with the interpreter. Its the same as writing a batch file, instead you are using Python, not batch or vbscript. Its better than opening IDLE and editing by hand one by one.
ghostdog74
Well I mean that you'd have to know the exact phrase you want to replace, without being able to actually browse the contents of the file. Perhaps I misunderstood what this does, but it looks like it takes a file and replaces all "search word"s with "new word"s. Or perhaps you misunderstood my question: I want to automate the opening of 15 files for editing.
Wallacoloo
And by editing I mean with the IDLE GUI.
Wallacoloo
i see. i misunderstood indeed.
ghostdog74