简体   繁体   English

Python 脚本打开文件或程序

[英]Python script to open a file or program

I am trying to make a simple python program which when run, it will ask a password and if the password is correct, it will open a certain file with a program (or open a program itself).我正在尝试制作一个简单的 python 程序,该程序在运行时会询问密码,如果密码正确,它将使用程序打开某个文件(或打开程序本身)。 Maybe not the password part but only how to open a file with a program or a program itself.也许不是密码部分,而只是如何使用程序或程序本身打开文件。 Thanks in advance.提前致谢。 ^_^ ^_^

https://docs.python.org/3/library/subprocess.html https://docs.python.org/3/library/subprocess.html

Above I have linked a library that does just this.上面我已经链接了一个这样做的库。 It allows you to pass in arguments to run an external command.它允许您传入 arguments 以运行外部命令。

Simply import it at the top of your program: import subprocess只需在程序顶部导入它:import subprocess

Read the documentation linked to find the method that you would like to use to solve your problem (subprocess.call())阅读链接的文档以找到您想用来解决问题的方法 (subprocess.call())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM