Напишите скрипт, который запускает команду с аргументами

1

Как написать сценарий в 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()
Теги:

1 ответ

2
Лучший ответ

Используйте модуль subprocess.

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()
  • 0
    Как раз то, что мне было нужно. Спасибо!!!

Ещё вопросы

Сообщество Overcoder
Наверх
Меню