gpt4 book ai didi

python - 编写一个脚本来运行带参数的命令

转载 作者:可可西里 更新时间:2023-11-01 11:43:58 30 4
gpt4 key购买 nike

如何在 Windows 中编写运行以下命令的脚本?

autoflake -i -r --remove-all-unused-imports %file_directory%

我的脚本是这样的:

file_directory = input("Enter directory name to run autoflake: ")

def autoflake_run():
try:
# I would like to run the command here.
except:
print("Path file error. Please make sure directory exists.")


autoflake_run()

最佳答案

使用 subprocess module .

import subprocess

file_directory = input('Enter directory name to run autoflake: ')


def autoflake_run():
try:
subprocess.run('autoflake -i -r --remove-all-unused-imports {}'
.format(file_directory))
except:
print('Path file error. Please make sure directory exists.')

autoflake_run()

关于python - 编写一个脚本来运行带参数的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50860166/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com