1

How can I write a script in Windows that runs the following command?

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

My script looks like this:

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 Answer 1

2

Use the 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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.