Adding to Josh's answer.
For the cleanest solution, you should use import
statements to pull code from another file. The way to achieve this would be for each file to have a main function that will serve as an interface. In addition, I also recommend using argparse if the files are command line programs.
If there is only 1 file to be called at a time, the program could look something like:
import argparse
import file1
import file2
parser = argparse.ArgumentParser(description='Run some files')
parser.add_argument('--file', type=str, dest='file', help='file name', required=True)
parser.add_argument('--options', dest='options', nargs='+')
args = parser.parse_args()
print(args.file)
if args.file == 'file1':
if args.options:
file1.main(*args.options)
else:
file1.main()
elif args.file == 'file2':
if args.options:
file2.main(*args.options)
else:
file2.main()
file1.py might look like:
def main(*options):
print('File 1', options)
And you call it like this: python3 menu.py --file file1 --options option1 option2