w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Call command-line oriented script from another python script

Would something like this work? Extract most of your code into a new function that expects arguments similar to the ones you send in via the command line. Then write a new function that gathers the command line arguments and sends them to the first function ...

def main(foo, bar):
    a = foo + bar
    print a

def from_command_line():
    foo, bar = get_command_line_args()
    main(foo, bar)

if __name__ == "__main__":
    from_command_line()

Then your other scripts can just call the main function.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.