Automate Stdin For Python Tests

Date Tags python

NOTE: The information in this post applies to Python 2.x only. See this post for Python 3.x support.

While working on Qprompt (a Python CLI based user input libary), I wanted to write some tests to check for regressions. The following lambda function allows stdin to be programmatically set:

import StringIO, sys
sys.stdin = StringIO.StringIO()
setinput = lambda x: [sys.stdin.truncate(0), sys.stdin.write(x),]

The following …

more ...

Python Pattern Matching, Sorta

Date Tags python

This trick is neat and potentially useful although maybe not very Pythonic:

txt = "two"
val = (
        1 if txt == "one" else
        2 if txt == "two" else
        3 if txt == "three" else
print val

The following form can be used instead:

txt = "three"
val = \
        1 if txt == "one" else \
        2 if txt == "two" else \
        3 if txt == "three" else \
print val
more ...

Resolutions That Work

Date Tags misc

Last January, I made a resolution to walk 3 million steps during the year. With the help of a cheap step counter and a spreadsheet, I am happy to say it may have been the first New Years resolution that I actually completed! While preparing a list of resolutions for 2016, the following criteria will help guarantee success:

  • Progress must be measurable! - Keep track of your progress periodically to make sure you will hit your …
more ...

Wordless - A Better Document Toolchain

Date Tags docs

I was raised during a generation where writing on a computer was virtually synonymous with using Microsoft Word (little has changed since). However, as I grew versed in the landscape of software development utilities, I knew there had to be a better way to write. For me, the perfect writing toolchain needed the following qualities:

  • Content should be portable.
  • Content should play nice with version control and diff tools.
  • Content should be grep-able.
  • Structure emphasized …
more ...

Introducing Qprompt

Date Tags python

Python is an excellent multipurpose language. However, when writing scripts (in the shell script sense), a decent command-line user interface is necessary. Qprompt is a library of simple command-line interface functions that should simplify common tasks. For example, to ask the user for an integer between 1 and 100, simply use the following:


Menus are straightforward as well:

menu = qprompt.Menu()
menu.add("1", "Item 1")
menu.add("2 …
more ...

Properly Plural Python Printing

Date Tags python

This one is kind of silly but sometimes you just want messages to use the proper plural case. Here is an example in Python 2 (with a little help from Qprompt):

import qprompt
num = qprompt.ask_int("How many beers?", vld=[1,2,3])
print "Okay, %u %s." % (
        "beer" if num == 1 else "beers")
more ...

Introducing The Unified Style Guide

Style guides are an important part of the software development process. They keep code consistent across projects and help maintain a level of cleanliness and professionalism. A few years ago, I realized there were no (to my knowledge) guides for general file and directory naming so I started one. Over time, I gradually updated it and eventually named it the Unified Style Guide with the lofty goal of one day expanding it to programming languages …

more ...

Hi, I am Jeff Rimko!
A computer engineer and software developer in the greater Pittsburgh, Pennsylvania area.