我使用了subprocess.popen,如下所示。以下linter建议出现在vscode中
try:
p = subprocess.Popen(
["python", "app.py"]
)
except:
traceback.print_exc()Consider using 'with' for resource-allocating operationspylint(consider-using-with)但我不知道该在哪里用“with”
发布于 2021-06-29 09:30:48
使用with为subprocess.popen()中的变量赋值。
try:
with subprocess.Popen(['python', 'app.py']) as p:
# code here
except:
traceback.print_exc()请注意,try/except还将捕获with主体中的异常。有关如何构建代码以仅捕获来自subprocess.Popen()的异常的信息,请参阅this answer。
https://stackoverflow.com/questions/68171548
复制相似问题