This week, I’m nearly 300 pages deep in Mark Lutz’s Learning Python, Second Edition and it’s still an easy to read book surprisingly. I know that technical books that I’ve read can be easy to read, or even entertaining, for the first few chapters but once you get into the real “meat” of the subject matter, it tends to dry up. I’ve started chapter 15 today and it’s now getting into the more advanced and concrete everyday use cases you’ll see: modules, module packages. I’m currently using it to rewrite a script I use at work for mass SPF record insertion in DNS zone files. I’ve skipped ahead some in the book to get an understanding of the re (regular expression) module of Python but unfortunately, Lutz doesn’t really spend a whole lot of time on it in this book or Programming Python (his other acclaimed O’Reilly book on Python). It’s really a shame because the module’s syntax is rather complex and can really take some getting used to if all you’re used to using are PCRE-types (Perl Compatible Regular Expressions) and sed. But it’s extremely nice being able to create groups like the following for code re-use:
matchdate = re.compile(r'?P
matchdate.sub(’CCYYMMDD’, ‘date’, count = 1)
Now I can use `date` to match anything from 20010101 to 20091231 which can obviously be very helpful if I’m busy doing inline edits on multiple files that can have multiple dates in them in that syntax. However, my only problem now is the fact that I can read zone files into a list (an array in other languages) and change the date inline but I can’t seem to take those values and write them back into a file. In bash, it’s easy:
sed 's/200[0-9][0-9][0-9][0-9][0-9]/CCYYMMDD/’ < file1 > file2
But when I try this with production code, I either end up with an empty file2 or I get an exception raised. Do I need to pickle the files?
Also, I’ve really grown to love pomegranate juice. I buy a bottle of POM(c) about once every two weeks since I use it as a supplement in my orange juice in the morning. I also have this great pomegranate tea that also has hibiscus and pepper in it. Yum!
Tags: 2 Comments

2 responses so far ↓
POM pomegranate black tea!!!
Yes, POM Pomegranate black tea is amazing but I was talking about the Celestial Seasonings Moroccan Pomegranate Red tea.