Reputation: 101
I am trying to open an existing .py file in the Python editor window using only a keyboard shortcut.
I have created a script that opens the file I am trying to open:
open(r'path\to\file.py')
and created a shortcut to this script and added a keyboard shortcut in the shortcuts properties window.
When I run the shortcut, it only runs the file but does not open it in the editor window.
Upvotes: 0
Views: 857
Reputation: 101
Now when I push ctrl-alt-w, this file opens up in the editor window.
Upvotes: 0
Reputation: 7206
you can try with:
import os
file_path = "C:/file/path/python_file.py"
os.system('notepad.exe ' + file_path)
or:
import subprocess
file_path = "C:/file/path/python_file.py"
subprocess.call(["C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4/bin\pycharm64.exe", file_path])
Upvotes: 0