Skip to content

Instantly share code, notes, and snippets.

@hbradio
Created September 19, 2016 20:15
Show Gist options
  • Save hbradio/228518562c409c7f9537c957d9d154d2 to your computer and use it in GitHub Desktop.
Save hbradio/228518562c409c7f9537c957d9d154d2 to your computer and use it in GitHub Desktop.
class Parser:
def grouped(self, iterable, n):
"s -> (s0,s1,s2,...sn-1), (sn,sn+1,sn+2,...s2n-1), (s2n,s2n+1,s2n+2,...s3n-1), ..."
return izip(*[iter(iterable)]*n)
def parse(self, filename):
print ">> Parsing " + filename
with open(filename, 'r') as f:
bytes = [byte for byte in f.read().split(' ') if len(byte) == 2]
words = self.pairwise(bytes)
return words
class Grapher:
def graph(self, val):
print val;
if __name__ == '__main__':
import argparse
ap = argparse.ArgumentParser('Hex Memory Parser')
ap.add_argument('-f', '--filename', type=str,
default="data.txt", help="Path to input file.")
args = ap.parse_args()
# try:
p = Parser();
g = Grapher();
g.graph(p.parse(args.filename));
# except:
# print "Caught unexpcted error"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment