LPTHW 13 & 14 and TOFU part 1

Today’s post combines exercises 13 and 14 since they conceptually build on and complement each other.

Exercise 13: Parameters, unpacking, variables: cats rats dogs & fish


In exercise 13, I wrote a script that accepts arguments. As instructed, you start out with three variables, but in the study drills I added a fourth. I also added the bonus raw_input() questions just to get more practice.

Exercise 14: Prompting and passing: or, how Lua learned to love my script

ex14pyExercise 14 combines the two concepts of raw_input (getting input from a user) and the command line options of exercise 13. In this exercise, we use argv, get a username, and make a prompt that is a variable (which I also change in the study drills). Finally, we use earlier-covered concepts of printing with %r and “”” to print over multiple lines.

I was a little nervous to do the study drill exercise, because they seemed intimidating. So I was a little blown away when, even tired, I got it on the first try. Can you tell a difference?


As I state in the comments, I changed the prompt variable from > to three hearts (<3<3<3), and I added another argument (lua). It was fun! But I’m really not sure if Lua likes my script or not. Knowing Lua, she probably doesn’t. Does this look like a cat who likes much of anything?

Nah. And especially not bows.

Moving on from cats and coding, two great loves, to another: cooking!

One of the questions I get asked the most, by vegetarians and nonvegetarians in equal measure, is how to properly treat tofu. Since this is kind of a big question, I want to address it in two posts. As with the kale, I’ll talk about prepping it into today’s post, and cooking it in tomorrow’s.

So. Tofu.

The tofu we’re dealing with today is the commonly-found water-packed variety. I contrast it with the “superfirm” shrink-wrapped packaged tofu that you can often find in Whole Foods Markets and well-stocked natural foods stores. That stuff is great, but it’s usually at least double the price of water-packed, and again, not as easily found. I’m a thrifty cook: can you guess my choice?


Yep. Water-packed.

Water is both our friend and our enemy. Friendly, because of the savings. But enemy, because water is devoid of flavor. Perhaps you already know that you can replace water with broth in soups, rice, and pasta for a more flavorful end product. In the case of tofu, you want to get as much water as possible¬†out of the block so that there’s room for other flavors. Tofu is more than happy to soak up delicious marinades… so long as you make room for them by pressing the water out!

First, you need to drain your tofu:


This next step is optional but recommended: I like to thoroughly rinse my tofu:


I know of at least one chef (Peter Berley, formerly of Angelica’s Kitchen) who not only rinses water-packed tofu but also sets it aside in filtered water for several minutes. He said it helps remove the tofu’s “bitter” taste from the soaking water, but I’ve never noticed a difference. Feel free to try it!

The next step is to press your tofu. This process will be wonderfully unique to your own kitchen and the stuff you have lying around. I’m very lucky to have a tofu press, shown below, but if you DON’T have a tofu press, be a good programmer/chef and google for your options. Couple quick recommendations:

1) in the sink, place the tofu between two cutting boards and place heavy things (cookbooks, canned goods) on top. be sure to stay nearby, though, as books & cans often slide.
2) also in the sink, place the tofu inside a pie plate or cake pan and then set another pie plate or cake pan of equal size on top. turn pie plates/cake pans over and stack heavy books on top. this is a pretty good method, and one I developed before my tofu press!

Of course, the easiest (and slightly more expensive) option is the tofu press. I’m still grateful to have received one as a gift from some wonderfully kind friends. I have a fancy-schmancy TofuXpress, but I’ve heard that the EZ Tofu Press is also quite good (and less than half the price!).


Step one: add tofu.


Step two: activate pressing!


Step three: find something else to do while the press does the work! Can you see how much water it’s pressed out after only a few minutes? That’s where your flavor/marinade/seasonings will go!

I prefer to let tofu press for at least an hour, or thirty minutes if I’m “pressed” for time, haha. You can also have several blocks going at once if you’re doing batch cooking. With the tofu press, I can leave it pressing in the fridge all day and just grab it when I’m ready.


Once it’s thoroughly pressed, I like to dry the block with a paper towel to remove any lingering moisture.

At this point, it’s just time to cube and cook:


Stay tuned for tomorrow’s post, where I’ll show you how to make tofu like this!


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: Exercises 7, 8, 9, 10… and kale!

Hi folks! Welcome to 2015!!

I’ve got a lot of ground to cover with Learn Python the Hard Way before I give a talk on Coding with Knives at PyTennessee on February 8, so let’s get started!*

Today I’m covering exercises 7, 8, 9, and 10 in one post because the concepts/practice are pretty similar. Namely, getting practice typing in code and making it run!

Exercise 7: Mary had a little… Cheese Burger


Two points of interest in exercise seven: 1) use single-quotes for short strings, e.g., ‘a’, or ‘snow’; and 2) a line longer than eighty characters is considered bad style in Python. Good to know!

Exercise 8: a little song/poem

ex8pyExercise eight covers slightly more complicated formatting of a string. Zed explains how %r is the “raw” format for getting debugging info about code. It will return exactly what you type, unless it needs to shorten something to be more efficient (he gives the example of changing ” to ‘.)

Exercise 9: eight days a week


Exercise nine introduces two ways to make a string go across multiple lines: 1) the “\n” newline escape sequence; and 2) three double-quotes.

Exercise 10: purr purr purr


Exercise 10 shows us \t to tab, \n to split a line, and a tabbed list.


It also has, as a bonus example, this silliness. My comment gives you a pretty good idea of how I reacted when the code ran.

Now that we’ve breezed through these exercises, let’s move on to something else quick and simple: kale! But wait, you didn’t expect me to say kale, did you? Kale is this giant, leafy, floppy, dirty, messy vegetable that perhaps you’ve found a bit unapproachable in the market:


Kale is big.


Kale is dirty. Sandy, muddy, gritty, grimy. Especially if you get the good (organic) stuff.


But don’t let the combination of giant + dirty scare you off. Prepping kale is easy and fast.

Take one leaf at a time and grab it by the base.


Start at the bottom and pull upwards, stripping the leaf from the stem. Be firm and sincere!


Pull all the way to the top, so that you’re left with only the greens in your hand.

Tear into pieces and drop into a bowl to be washed.


See? easy! That took about two minutes.


Rinse thoroughly: at least three changes of water. The first two rinses will be extremely cloudy. Subsequent rinses should run clear (or slightly greenish from the chlorophyll, I guess). Be sure to swish vigorously with your hands to loosen and dirt, sand, or grit.

I used lacinato (sometimes called dinosaur) kale here, but you can use this same method with curly kale. Just strip the leaves from the stem, tear into pieces, rinse, and spin in a salad spinner to remove extra moisture, if desired. Easy, and unlike collards, no knife is required.

Kale is also super fast and easy to cook, but you’ll have to wait til tomorrow’s post to get my recipe for garlicky kale with four flavors (hot, sour, salty, & sweet). See you then!

*I failed to mention? Shame on me! That’s right, I’m totally thrilled and honored to be giving at talk at PyTennessee on my experience learning Python with Coding with Knives. The talk will be in the afternoon on Sunday, February 8 at the Nashville School of Law in Nashville, Tennessee. Learn more about the conference and register to attend here!