import argparse class WriteRecipe(argparse.Action): def __call__(self, parser, namespace, values, option_strig=None): filename = raw_input('Name of Recipe: ') recipe = open(filename + '.txt', 'a') recipe.write('Recipe Name: ' + filename + '\n Ingredients:\n') print ('Ingredients') while True: ingredients = raw_input() if ingredients == 'exit': break elif ingredients == 'method': recipe.write('\n \n Method:\n' + '\n' + ingredients + '\n') else: recipe.write(ingredients + '\n') recipe.close() recipeapp = argparse.ArgumentParser(description='A small Recipe Collection Program') recipeapp.add_argument('add', action=WriteRecipe, help='Add a recipe') args = recipeapp.parse_args()