LPTHW 18, 19, 20, 21… beer battered and fried

Exercise 18: Names, Variables, Code, Functions

Exercise 18 offers a formal introduction to functions. The author explains that functions basically:

1) Name pieces of code (the way variables name strings & numbers)
2) Take arguments (the way scripts take argv)
3) Let you make your own “mini-scripts” or “tiny commands” using 1 & 2

He explains how to create a function and then we walk through four functions that work like our previous scripts. I typed and ran the functions without issue.

I really enjoyed this one. Compared to previous exercises, the introduction of functions means I’m now working with code that’s closer to what I’ve observed my smart friends writing, and what I saw at the PyATL meet-up Thursday night. It’s very encouraging to see something familiar.

In the study drills, I made a “function checklist”: steps to follow/things to check when writing and calling functions. To take the exercise a bit further, I re-wrote the functions to make sure I was really getting it. I made one ValueError, three SyntaxErrors, and 2 TypeErrors, but it was great, because each time it returned an error, I got to go investigate what I needed to fix. It was an adventure!


The above shows how I adjusted the original exercise: butterflies, caterpillar feet, rainbows, and stolen sandwiches.

Exercise 19: Functions and Variables


In exercise 19, we get more practice with functions. Above shows the continued practice of making comments explaining what’s going on.


For more practice, I got creative and wrote a swoon-worthy flower_garden function of celosia and dianthus.

Exercise 20: Functions and Files


Exercise 20 combines knowing about functions, files (and how to read and write them), and then creating “file helpers”. I’m not really sure what the author means by file helpers – anyone reading care to share any light, here? What I do know is that this script contains three functions that essentially let us print lines from a three-line text file. I continue to find that making comments around the code helps me understand what it’s going.

Exercise 21: Functions Can Return Something


Finally, in exercise 21, I used return to set variables to be a value from a function. The author explains the two-way nature of functions. We pass in values, but they can also pass our values that we can assign to variables. In this example, we use functions to do an algebraic-like equation at the bottom, though it’s somewhat nonsense and for teaching purposes only.

These lessons seemed very straightforward to me, which makes me nervous, because the author keeps mentioning how difficult and mindblowing the exercises are. I definitely think that finally seeing code that looks familiar is bolstering my confidence. I also think that some of these concepts are fairly simple, but the author’s explanation is occasionally more extravagant than necessary. This has to do with teaching style. You never know if you’re going to connect with someone’s teaching style until you’re at their mercy, and without an interactive way to ask questions or probe for new examples, one is left emailing her smart friends for further explanation!

Exercise 22 is all about reviewing chapters 1 – 21 to make sure I’m truly not missing anything. It’ll probably take hours, but by the time I’m finished, hopefully I’ll have confidence that I truly do know what’s up.

Now, moving on to the cooking portion…

In my last post, I mentioned that I was setting you up to learn how to do tofu as little cubes that you brown in a skillet and add to an assortment of dishes: noodles, toppings for salads, a breakfast side.

But as I write this, it’s Saturday morning, and I’ve decided to put my tofu cube lesson on hold in favor of a more decadent brunch treat: the beer-battered-and-fried tofu steak for use with biscuits and gravy, waffle sandwiches, or as a main course with skillet potatoes. Behold: the frying tofu steak in action:


Frying on one side.


Frying on the other.


Look at that golden-brown crispiness.


Behold! The “wafflewich” a la Bianca & Cookin’ Crunk

Are you ready?

Like the function exercises above, there’s a lot here. By the time we’re finished, you’ll not only know how to make an amazing crispy fried tofu steak, but you’ll also master a marinade and a seasoned flour. Flavorwise, think of this dish like fried chicken, since tofu absorbs flavor in much the same blank-slate way that chicken does. You’re gonna love it!

Here are the steps:

1) Press tofu as directed in previous post.
2) Slice tofu lengthwise into about six to eight equal pieces (depending on how significantly your tofu pressed).
3) Prepare marinade as directed below and allow tofu to soak a few hours, or overnight.
4) Prepare a seasoned flour as directed below.
5) Crack open a good beer. Why? So you can enjoy drinking what you don’t use in the recipe. Also, if you’re not already always cooking with the kind of beer and wine you would drink, start doing that.
6) Prepare a workstation comprised of the a) the bowl of marinated tofu, b) bowl of seasoned flour, c) bowl with about half your beer poured into it.
7) Heat a cast-iron or other heavy skillet with oil for frying. Please check out pictures above to get an idea of depth and temperature of oil, and tools used. Let me know if you have questions.
8) Designate one hand wet and one hand dry! Decide before starting which hand you’re going to use to dip into wet ingredients, and which into dry. If you mess up and use the same hand for both, you’ll be ok, but it does get messy. Best to try to always use the same hand for dipping into wet and the other for dipping into dry.
9) Prepare a place to drain the fried tofu of excess oil. This usually looks like a plate with paper towels on it.

Now that you’re all set up and your oil is hot, the basic steps for cooking the tofu are as follows:
1) Grab a piece of tofu.
2) Dip it into the seasoned flour.
3) Dip it into the beer.
4) Dip it into the flour again.
5) Gently place into the hot oil and allow to cook on one side 3 – 4 minutes, or until golden brown.
6) Use tongs to turn tofu over and cook on the other side, 3 – 4 minutes.
7) Use tongs to remove from oil and place on paper towels for draining.

Once you’ve cooked all your “steaks” you can pair them with sides and smother with gravy to eat with a knife and fork, or press between a waffle and drizzle with maple syrup for a “chicken and waffle” sandwich. This creation is an institution here in the south thanks to Gladys Knight and others, but I’d like to give a special thanks to Bianca Phillips of Cookin’ Crunk for inspiring this post with her amazing Southern Fried Tofu Chicken Wafflewich. If you enjoy southern recipes like this, you should definitely get her book and check out her blog.

Master Recipes

How to make a marinade for tofu:

Conceptually: Typically it will start with vegetable broth and then you’ll add seasonings to enhance its flavor: onion powder, chopped raw garlic, a tablespoon of soy sauce or miso (dissolved in a small amount of water), nutritional yeast, poultry seasoning, dried herbs. For acidity, adding freshly-squeezed lemon juice or some apple cider vinegar. For a mysterious smoky element, try adding a chopped chipotle in adobo, some smoked paprika, or a few drops of liquid smoke.

Note: because of tofu’s high fat content, you do not have to add oil to tofu marinades!

Specifically: A measured version of this might look like: 2 cups vegetable broth with 3 tbsp soy sauce or 2 tbsp dark miso dissolved in water, 3 tbsp nutritional yeast, a couple of cloves of minced garlic, some freshly-ground black pepper, and teaspoons each onion powder, poultry seasoning, and your favorite dried herb (marjoram and thyme are nice).

How to make a seasoned flour:

Conceptually: Like vegetable broth in the marinade, the main component of a seasoned flour is the flour itself. You can use whole wheat pastry or regular unbleached all-purpose. As with the marinade, you’re just adding seasonings to enhance the flavor of the flour. What you add to the flour should suit your own taste!

Specifically: A good seasoned flour might consist of two cups of flour with a couple of teaspoons each of garlic powder, onion powder, poultry seasoning or dried herbs, smoked paprika, nutritional yeast, a teaspoon of salt and some dashes of freshly-ground black pepper. I also like to replace a little bit of the flour with cornmeal for textural interest; perhaps 1 3/4 cups flour and 1/4 cup cornmeal.

Substitutions for the beer:

Not a beer drinker, or don’t have any on hand? It’s perfectly acceptable to substitute some milk (I prefer unsweetened soymilk) for the beer. What I’ve described above is an extremely common and versatile battering process for protein, which consists of a dip in liquid, then in flour, then in liquid again, then in flour again, then in hot oil frying. The multi-step dipping in flour & liquid is what builds the crunchy “shell” to the protein. Milk will work just fine.

See you in the next post, where I covered what I learned while reviewing 21 exercises and a new recipe or cooking lesson.


LPTHW: Exercises 11 & 12 and a kale recipe

In exercises eleven and twelve, we move on from simple (and boring?) things like printing to getting data into our little programs.

Exercise 11: Asking questions

Zed explains that software is mostly 1) taking input from a person; 2) changing it; and 3) printing something to show how it changed. So far I’d just been printing strings, not getting any input from the user. In this exercise, I use raw_input to ask questions (…of myself) about basic facts.

Exercise 12: Prompting people

Exercise 12 demonstrates a new way to write the material covered in eleven, as shown above.

I also used the pydoc command to learn about raw_input, open, file, os, and sys, as directed. It’s certainly faster than Googling!

Finally, I wrote another little “form” to ask questions using the new style:

12bpyFunny that the day I move on from simplest concepts, I’m sharing one of my easiest recipes! In fact, I’m not even sure you can call it a recipe, but rather a series of guidelines for success with kale. Yesterday I demonstrated how to prep it, so be sure to check that out if you haven’t already.

Today’s recipe is for kale with “four flavors”: hot, sweet, sour, and salty.


Pictured above: organic vegan cane sugar, apple cider vinegar, red pepper flakes, fresh garlic, and soy sauce.

Kale with four flavors (serves two or one very hungry person)

  • one bunch kale, prepped as directed
  • as much chopped or minced garlic as you desire. I used four giant cloves.
  • tablespoon of oil
  • red pepper flakes, to taste
  • apple cider or rice vinegar, to taste
  • soy sauce, to taste
  • sugar, to taste

Warm oil in pan. Add garlic. Quickly cook til fragrant, about 30 seconds – 1 minute. Partway through, toss in some red pepper flakes. If garlic is cooking too quickly, remove from heat. Do not overcook and do not allow garlic to burn.


Add cleaned kale and toss thoroughly to coat with garlic and red pepper flakes. Some of this garlic got a little browner than I would have liked because the pan was hotter than I realized, but I decided to share the image (and story) anyway to show you that even folks who have been cooking for a long time occasionally slip up. When this happens, just put a descriptive adjective in front of the noun when serving it: voila, it’s kale with crispy garlic!


Sprinkle kale with apple cider vinegar, soy sauce, and sugar to taste:


If you’re completely uncertain about this, start with a tablespoon of vinegar, two teaspoons of soy sauce, and a teaspoon of sugar. Mix well over medium, medium-high heat; kale should be wilting and releasing juices, cooking down significantly:


Continue to toss thoroughly so that flavors combine. Taste for seasoning and add more of what you think is missing. This is your chance to experiment with strong flavors and discover what works for you!


And there you have it: a lovely little bowl of kale that you seasoned to your own taste. Well done!

Bonus lesson: you can treat swiss chard and collards the same way, just vary the cook times. If kale takes about ten minutes to cook down, swiss chard will finish in 6 – 8 (it’s tender!). Collards will need around 30 (tougher!), and you might have to splash in a few tablespoons of vegetable broth. Make it happen!


LPTHW: Exercise 3: Numbers and Math and caramelized onions

I use math a lot in my daily life. I’ve managed complicated budgets for several businesses (including my current job) and have been doing my own taxes (accurately!) for over a decade. Most of the time I’m in the grocery store I’m running numbers, determining sale prices, calculating total costs. Same goes for the kitchen — frequently I’m altering recipes, which requires an ability to do conversions on the fly.

Yet, when I saw that this exercise was about “numbers and math”, I froze. Numbers and math! It must be some basic, primal fear coming out. I’m glad I didn’t let it stop me:


Not so scary!

In the extra credit, Zed asks us to go back and comment out each line, explaining what is happening:


The only thing that tripped me up was modulus. In Zed’s words: “Another way to say it is, ‘X divided by Y with J remaining.’ For example, ‘100 divided by 16 with 4 remaining.’ The result of % is the J part, or the remaining part.” Okay.

He also has us start Python and use it as a calculator. I didn’t do anything too fancy:


Next up, he has us write another little .py file that does some math. I couldn’t figure out anything I needed to determine, so I just made something up.


I counted some hypothetical fruit. I’m looking forward to covering variables because I think it would have made my little example easier to write.

Finally, he stressed the importance of using “floating numbers” so I went back and re-wrote my little program to use them. Accuracy wasn’t an issue with this example, but it might be in the future, so floating point numbers seem like a good idea.

For today’s cooking basics lesson, I’m covering caramelized onions. Yesterday I made a pot of my favorite fordhook lima beans. The secret to their deliciousness is a generous base of caramelized onions.


Caramelizing means cooking over low-ish heat for a long time in order to brown the naturally-occurring sugars in the onions. The formerly pearly-white cubes are transformed into a rich golden-brown (or deeper!) color with a rich, savory-sweet flavor.


Start by uniformly chopping onions. A lot of folks go for long thin slices, but I wanted cubes. The small pieces look better than strands in the finished dish.

Warm or melt your fat of choice over medium heat. I used Earth Balance margarine, but you could also use coconut oil or olive oil.

Add the onions.

Stir to thoroughly coat onions with fat.

After 10 minutes on medium heat. Use a stiff, well-made spatula to scrape up the bits of browning goodness.

After 20 minutes on medium heat.

Scrape scrape. After thirty minutes on medium. I turned it down to medium low.

Forty minutes…

One hour.

What a difference a little time and heat makes! I did not add any salt, sugar, or liquids to enhance the caramelization process.

If you’re making a soup or a pot of beans, at this point you simply add other ingredients and simmer until fully cooked. As I mentioned above, I used fordhook lima beans and simmered them until the broth formed a kind of rich oniony gravy. A perfect dinner!


LPTHW: Exercise 2: Comments and Chana Masala

Exercise two is about comments. I already knew how to comment out code, so this was an easy one.


Zed explains that comments are important because they give you a way to explain, in plain English, what something does. Comments help future readers of your code understand what’s going on. They also permit you to disable parts of your program if you need to.

Comments in Python use the hash character (#, octothorpe), but today I learned that other languages use other symbols. I noticed this while reading Erik Dietrich’s post “Rapid Fire Craftsmanship Tips“. He gives a very specific example of when a certain type of comment is not so helpful.

Taking time to document what I’m doing helps with the learning process — it makes things “stick”. This is exactly why Zed often suggests that we go back and write comments around seemingly easy exercises. It can feel tedious, but I still do it.

In related news, “Very” Early Bird tickets for PyTennessee opened today and I got one! $50 for an earlybird ticket for a two-day conference is a steal, especially if I can find a couch to sleep on for the weekend. Hopefully I’ll be pretty far along in my journey by next February and will learn a lot from the experience.

Today is October first and in the spirit of my favorite month of the year I want to share one of my favorite recipes: chole (chana) masala. It’s one I love to make for crowds and dinner parties because it always pleases. I also enjoy preparing it for sick friends as it keeps exceptionally well, actually improving the longer it sits in the fridge (up to a point!). It is a variation of the recipe shared here. Let me know if you have any questions.Chana masalaIngredients:

  • 1/4 cup coconut oil (unrefined works)
  • 1 very large yellow onion, thinly sliced (sweet onions also work — I’ve had great luck with giant vidalias)
  • 1 small jalapeno or other hot pepper, seeded and minced (wear gloves!)
  • 1 1/2 heaping tablespoons minced fresh garlic
  • 1 heaping tablespoon minced fresh ginger
  • 1/4 – 1/3 cup finely chopped fresh cilantro (omit if averse)
  • 2 28 oz cans diced organic tomatoes in juice, undrained (no basil or seasonings added)
  • 1/2 teaspoons salt (add more to taste if your tomatoes are unsalted, but most are salted)
  • 3 1/2 – 4 cups cooked chickpeas
  • 1 tablespoon agave nectar
  • Juice of one small lime or 2 teaspoons tamarind concentrate
  • 1/2 cup coconut cream
  • Post Punk Kitchen spice blend
    • 1 tablespoon plus 1 teaspoon ground cumin
    • 1 tablespoon ground coriander
    • 1 teaspoon ground turmeric
    • 1/2 teaspoon fennel seeds, chopped
    • 1/2 teaspoon cardamom
    • 1/4 teaspoon cinnamon
    • 1/8 teaspoon ground cloves
    • 1/4 teaspoon ground cayenne (add more or less to taste)

Please note that in this and any recipe, it’s incredibly important to use fresh, fragrant spices for the best-possible dish. I’ll cover proper storage of spices in a later post, but for now: if your spices smell like sawdust, they’ll probably taste that way, too. Toss ’em and invest in something new.


Preheat one of your largest pans or pots over medium heat. I use a large, heavy-bottomed pan because I have one and it helps the tomatoes cook down faster, but if you don’t, you can use a large pot.

Make your spice blend by combining spices in a bowl and whisking with a fork or small whisk.

When the pan is hot, add coconut oil. Allow it to warm. Add the onion (you should hear it sizzle) and cook about ten minutes. Onion will become soft and golden, and depending on how hot your pan is, may brown some. You may elect to leave the onions mostly undisturbed, or give them a good toss every few minutes or so. Just don’t burn them!

After about ten minutes, add the hot pepper, garlic, and ginger all at once, and stir constantly for about 30 seconds to a minute. Add the spice blend and stir constantly for about another minute. Make sure the onion-pepper-garlic-ginger mixture is thoroughly coated.

Add the tomatoes and mix well, scraping the bottom of the pan to get all that sauteed goodness. Add salt and chickpeas. Cover the pan and raise heat to medium-high, but once it has reached a strong simmer, uncover. Reduce heat to medium. Allow to simmer enthusiastically for about twenty minutes, stirring every few minutes or so. Be mindful of the heat – you don’t want anything to burn. The point is to get the tomatoes to cook down so that the dish is thick and saucy rather than watery.

Once it’s reached a good consistency, stir in about a half a cup of coconut cream. You can use more. Creaminess is wonderfulness.

Adding my secret ingredient - the coconut cream!

Adding my secret ingredient – the coconut cream!


Adding the tamarind

Add the lime or tamarind and agave nectar. Taste for seasonings and adjust as necessary. Add cilantro if using. Remove from heat and allow to sit for about ten minutes.

Thanks to Isa and Terry at the Post Punk Kitchen for inspiring me with this recipe.