Python String Index Replace

Date Tags python

Python does not allow string to be modified via indexed assignment. For example, a = "hello"; a[1] = "x" will produce a TypeError: 'str' object does not support item assignment error. Grr!

The following one-liner stridxrep() can be used if the need ever arises:

a = "hello"

# Python doesn't allow the following:
# a[1] = "x"

# A 'string index replace' function.
stridxrep = lambda s, i, r: "".join([(s[x] if x != i else r) for x in …
more ...

Introducing CsvPal

Date Tags python

When picking a simple but useful data format, CSV is tough to beat. However, looking through large files can be cumbersome. For this reason, I threw together CsvPal, a simple command-line utility for filtering out columns of interest. Check it out if you frequently work with large CSV files.

more ...

Quickly Render AsciiDoc Notes

AsciiDoc is a great markup format for writing notes. In fact, almost all computer-based notes I write are in AsciiDoc; it is simple yet expressive, portable, and most importantly, grepable.

While Vim is my primary tool for viewing AsciiDoc files, looking through the raw text can leave a bit to be desired. Longing for the beautifully rendered output that only an AsciiDoc file can provide, I threw together the following simple (and ugly) Python script …

more ...

Parsing With Parsimonious

Date Tags python

Recently I have been playing around with a parsing library for Python called Parsimonious. So far, I have been very impressed with it. Examples can be a bit hard to find; the following is a simple CSV parser:

from parsimonious.grammar import Grammar
from parsimonious.nodes import NodeVisitor

class EntryParser(NodeVisitor):
    def __init__(self, grammar, text):
        self.entry = {}
        ast = Grammar(grammar).parse(text)
        self.visit(ast)
    def visit_name(self, n, vc):
        self.entry['name'] = n …
more ...

Docopt

Date Tags python

While browsing YouTube recently, I stumbled upon a video about a great third-party Python module called Docopt. It greatly simplifies writing command-line utilities; instead of writing custom logic using the standard library optparse or argparse modules, you simply write the usage docs for the utility and Docopt handles the parsing. Check out the documentation; there are some great examples that really showcase the power of this module.

more ...

PopPage

Date Tags python

Recently, I had a need for a very lightweight static website generator. The idea was to have AsciiDoc and Pandoc handle the markup to HTML conversions while the generator would simply apply the HTML content to a Jinja2 template. The result was PopPage, a simple command-line driven website generator. It plays nicely with native Windows batch scripting and I plan on providing a few examples in the GitHub repo shortly.

more ...

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