Skip to content

Instantly share code, notes, and snippets.

@stuartcampbell
Created June 1, 2015 15:36
Show Gist options
  • Select an option

  • Save stuartcampbell/f70fbda046791fca7f25 to your computer and use it in GitHub Desktop.

Select an option

Save stuartcampbell/f70fbda046791fca7f25 to your computer and use it in GitHub Desktop.
Iterating over 3 lines at a time (for stdout) in Python
import subprocess
import itertools
# execute some command
since = "--since='{0}-{1}-1'".format(str(year), str(month))
until = "--before='{0}-{1}-{2}'".format(str(year), str(month), str(days_in_month[month-1]))
args = ['git', 'log', '--pretty=format:"%ai %aE"', '--shortstat', since, until]
sub = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True, cwd='/path/to/git/repo/clone')
for line1,line2,line3 in itertools.izip_longest(*[sub.stdout]*3):
# Do stuff with line1, line2, line3...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment