如何在 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/