Skip to content

The Geek Worker

Random Computer Issues And Things That Fixed Them For Me

  • About this Website
  • Helpful Links

Hello, Python!

July 7, 2007 by geekworker

I’ve independently talked about Python with Harry and Lars last week. Conclusion: Python seems to be “the” script language to learn if you want something versatile and hate Perl.

Today I needed a small script: Find me all the 4-lettered family names from the US Census data. Usually I’d simply do that with awk. But what better opportunity to actually start using Python?

I have the family name list in ASCII form. Nicely formatted in columns with whitespace separators. All I need is a small Python script that will loop over stdin and match as required. No huhu:

import sys
import re

while True:
    line=sys.stdin.readline()
    m = re.match(‘^[A-Z]{,4} ‘,line)
    if m != None:
        print m.string[m.start():m.end()]
    if line == “”:
        break

That wasn’t so difficult.

Posted in ArticleTagged Python
Next story SVN Stalling

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Inkscape: “Document Properties” Window Not Showing Up
  • Synology Drive Client does not connect on Apple MacOS
  • “The iTunes Store is temporarily unavailable. Please try again later” when trying to subscribe to Podcast
  • “Access Denied” Errors with TortoiseSVN on Samba
  • Keyboard and Mouse Microstutters with a Dell Latitude Notebook

Recent Comments

  1. Bart on Gigabyte OSD_Sidekick: “Please check if your USB cable is connected”
  2. Jason on Sony Vegas and Sony Movie Studio: No Audio Tracks In mp4 video filefound
  3. DaReclama on OpenVPN: IP packet with unknown IP version seen
  4. vilva on Excel Formula to get Number of Days in a Month
  5. Michael (Micky) Avidan on Excel Formula to get Number of Days in a Month

© 2026 The Geek Worker. Proudly powered by WordPress.