Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Os.startfile in Windows.
#11
(Aug-02-2019, 09:06 PM)Gribouillis Wrote: So does it mean that there is no safe way to launch an editor for a python file in windows without knowing the editor?
Can just force to open to eg in notepad that's in all Windows version.
import subprocess

subprocess.run(['notepad', 'hello.py'])
Reply
#12
Snippsat Wrote:Can just force to open to eg in notepad that's in all Windows version.
I think I'm going to do that and add a configuration option to let the user choose another editor.
Reply
#13
Quote:As snippsat wrote:
It will all depend on what file association .py is set to in Windows.
If i set file association in Windows for .py to Notepad++,then this code will open hello.py in Notepad++.

After associating Notepad++ to Python file,
import os
os.startfile(<absolute path of the python file>) #Absolute path: Only incase os.chdir is not being used 
If I run this code, then it is opening in Notepad++

Same happens with

import webbrowser
webbrowser.open(<absolute path of python file>)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020