starting Python IDLE from command line to edit scripts

后端 未结 7 1712
北荒
北荒 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: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.

提交回复
热议问题