Open a text file using notepad as a help file in python?

后端 未结 6 1947
攒了一身酷
攒了一身酷 2020-11-29 08:28

I would like to give users of my simple program the opportunity to open a help file to instruct them on how to fully utilize my program. Ideally i would like to have a littl

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 08:50

    If anyone is getting an instance of internet explorer when they use import webbrowser, try declaring the full path of the specified file.

    import webbrowser
    import os
    
    webbrowser.open(os.getcwd() + "/path/to/file/in/project")
    #Gets the directory of the current file, then appends the path to the file
    

    Example:

    import webbrowser
    import os
    
    webbrowser.open(os.getcwd() + "/assets/ReadMe.txt")
    #Will open something like "C:/Users/user/Documents/project/assets/ReadMe.txt"
    

提交回复
热议问题