如何在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()
答案 0 :(得分:2)
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()