简体   繁体   English

从另一个带有命令行参数的Python脚本中打开IDLE

[英]Opening IDLE from another Python script with command line paramteters

I am looking to open a Python script in edit mode in IDLE by passing in a directory from another Python script. 我想通过传入另一个Python脚本的目录在IDLE中以编辑模式打开Python脚本。 I understand that I can use os.system to execute idle.py but I then don't know how to pass the appropriate -e parameter and get it to use a specific directory ie open something.py in diredtory C:\\Python all from the original Python script. 我知道我可以使用os.system执行idle.py,但是随后我不知道如何传递适当的-e参数并使其使用特定目录,即在目录C:\\ Python中打开something.py原始的Python脚本。

Thanks for your help, 谢谢你的帮助,

Ben

You can use subprocess.call() . 您可以使用subprocess.call() By setting shell = True , the function treats the string as a literal shell command. 通过将shell = True设置shell = True ,该函数将字符串视为文字Shell命令。 Modify the paths as you see fit. 根据需要修改路径。

import subprocess

subprocess.call(r'C:\Python27\Lib\idlelib\idle.py -e C:\Python27\something.py',
                shell=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM