All pastes #2067273 Raw Edit

Untitled

public text v1 · immutable
#2067273 ·published 2011-05-23 05:08 UTC
rendered paste body
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()