1

I am looking to open a Python script in edit mode in IDLE by passing in a directory from another Python script. 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 i.e. open something.py in diredtory C:\Python all from the original Python script.

Thanks for your help,

Ben

0

1 Answer 1

2

You can use subprocess.call(). By setting shell = True, the function treats the string as a literal shell command. 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) 
Sign up to request clarification or add additional context in comments.

6 Comments

Should the not use forward slashes? For other operations, like os.chdir, an error is returned if forward slashes are not used, even on a Windows box.
I am afraid I think the rest of my program is so broken other errors are coming up before it even gets to this code. This is part of my first attempt at OOP programming so...
@fluffybonkers Well, if it does return a syntax error, flip the slashes.
Just tested in isolation. It works but it opens up multiple IDLE windows.
@fluffybonkers Try it without the -e?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.