
def csv():

    def Receipt(meta, body, variables):
        output = []

        def add(s) : output.append(s)

        if "store" in meta:
            add("# Store: {}".format(meta["store"]))
        if "date" in meta:
            add("# Date: {}".format(meta["date"]))
        if "location" in meta:
            add("# Location: {}".format(meta["location"]))

        add(body)

        return "\n".join(output)

    def ItemList(s): return s
    def ItemListSep(): return "\n"

    ## Could also be used to collapse the fields, or exclude some.
    def Item(name, cost, discount, tax):
        return "{}, {}, {}, {}".format(name, cost, discount, tax)

    return {
            "Receipt" : Receipt,
            "ItemList" : ItemList,
            "ItemListSep" : ItemListSep,
            "Item" : Item,
        }


def Receipt(meta, body, variables):
    output = []

    def add(s) : output.append(s)

    if "store" in meta:
        add("# Store: {}".format(meta["store"]))
    if "date" in meta:
        add("# Date: {}".format(meta["date"]))
    if "location" in meta:
        add("# Location: {}".format(meta["location"]))

    add(body)

    return "\n".join(output)

def ItemList(s): return s
def ItemListSep(): return "\n"

## Could also be used to collapse the fields, or exclude some.
def Item(name, cost, discount, tax):
    return "{}, {}, {}, {}".format(name, cost, discount, tax)

Convert CSV writer to a module definition.
Convert CSV writer to a module definition.

Use __import__ to import it as a dictionary.

+ def Receipt(meta, body, variables):
+     output = []
  
- def csv():
+     def add(s) : output.append(s)
  
-     def Receipt(meta, body, variables):
-         output = []
+     if "store" in meta:
+         add("# Store: {}".format(meta["store"]))
+     if "date" in meta:
+         add("# Date: {}".format(meta["date"]))
+     if "location" in meta:
+         add("# Location: {}".format(meta["location"]))
  
-         def add(s) : output.append(s)
+     add(body)
  
+     return "\n".join(output)
-         if "store" in meta:
-             add("# Store: {}".format(meta["store"]))
-         if "date" in meta:
-             add("# Date: {}".format(meta["date"]))
-         if "location" in meta:
-             add("# Location: {}".format(meta["location"]))
  
-         add(body)
+ def ItemList(s): return s
+ def ItemListSep(): return "\n"
  
-         return "\n".join(output)
+ ## Could also be used to collapse the fields, or exclude some.
+ def Item(name, cost, discount, tax):
+     return "{}, {}, {}, {}".format(name, cost, discount, tax)
  
-     def ItemList(s): return s
-     def ItemListSep(): return "\n"
- 
-     ## Could also be used to collapse the fields, or exclude some.
-     def Item(name, cost, discount, tax):
-         return "{}, {}, {}, {}".format(name, cost, discount, tax)
- 
-     return {
-             "Receipt" : Receipt,
-             "ItemList" : ItemList,
-             "ItemListSep" : ItemListSep,
-             "Item" : Item,
-         }
- 
- 
Convert CSV writer to a module definition.
## Code Before:

def csv():

    def Receipt(meta, body, variables):
        output = []

        def add(s) : output.append(s)

        if "store" in meta:
            add("# Store: {}".format(meta["store"]))
        if "date" in meta:
            add("# Date: {}".format(meta["date"]))
        if "location" in meta:
            add("# Location: {}".format(meta["location"]))

        add(body)

        return "\n".join(output)

    def ItemList(s): return s
    def ItemListSep(): return "\n"

    ## Could also be used to collapse the fields, or exclude some.
    def Item(name, cost, discount, tax):
        return "{}, {}, {}, {}".format(name, cost, discount, tax)

    return {
            "Receipt" : Receipt,
            "ItemList" : ItemList,
            "ItemListSep" : ItemListSep,
            "Item" : Item,
        }


## Instruction:
Convert CSV writer to a module definition.
## Code After:
def Receipt(meta, body, variables):
    output = []

    def add(s) : output.append(s)

    if "store" in meta:
        add("# Store: {}".format(meta["store"]))
    if "date" in meta:
        add("# Date: {}".format(meta["date"]))
    if "location" in meta:
        add("# Location: {}".format(meta["location"]))

    add(body)

    return "\n".join(output)

def ItemList(s): return s
def ItemListSep(): return "\n"

## Could also be used to collapse the fields, or exclude some.
def Item(name, cost, discount, tax):
    return "{}, {}, {}, {}".format(name, cost, discount, tax)
