首页 > 解决方案 > 我可以用 os.system 或 os.startfile 打开什么类型的文件?

问题描述

我可以用os.system或打开什么类型的文件os.startfile?我知道你可以使用:

paths,
file.txt,
file.py,
file.js,
file.css,

ETC..

但是如何打开 Chrome 和其他应用程序

标签: pythonoperating-system

解决方案


Python os.startfile 是一个非常有用的命令。您不仅可以打开文件,还可以打开应用程序。一种方法是单击应用程序并复制路径。然后将该路径放入 os.startfile() 中。请记住,它必须是 exe 或 lnk 文件。这是和示例:

os.startfile('Chrome.exe')

当您编写此代码时,python 将为您打开 Chrome。要在 chrome 中打开链接,您可以通过以下方式使用 webbrowser 模块:

webbrowser.open_new_tab('https://web.whatsapp.com/')

谢谢你!我希望这对你有用!


推荐阅读