Skip to content

Instantly share code, notes, and snippets.


Gary van der Merwe garyvdm

  • LSD Information Technology
  • Johannesburg, South Africa
View GitHub Profile
garyvdm /
Created May 12, 2014
Alternative to decorator, which allows arguments to be returned form the setup function, and passed to the test and teardown functions.
def with_setup_args(setup, teardown=None):
"""Decorator to add setup and/or teardown methods to a test function::
@with_setup_args(setup, teardown)
def test_something():
" ... "
The setup function should return (args, kwargs) which will be passed to
test function, and teardown function.
garyvdm / headtail
Last active Aug 29, 2015
head and tail a stream
View headtail
#!/usr/bin/env python
import argparse
import sys
import collections
parser = argparse.ArgumentParser(description='Show the first 10, and last 10 lines of a file.')
parser.add_argument('infile', nargs='?', default=sys.stdin,
help='Input file. Defauts to stdin if not provided.')
parser.add_argument('outfile', nargs='?', default=sys.stdout,