#! /usr/bin/env python3

import argparse
import sys
import json

parser = argparse.ArgumentParser(description="Create byte-wise n-gram distribution",)
parser.add_argument('-n', default=1, help="Size of n-grams")
parser.add_argument('-o', '--output', default=None, help="File to write output to")
parser.add_argument('input', help="The file to be n-gram analyzed")

args = parser.parse_args()

file_name = args.input
n = int(args.n)
output = args.output

distribution = dict()

with open(file_name, "rb") as f:
    f.seek(0,2)
    end = f.tell()
    f.seek(0)
    bytes = f.read(n)
    while f.tell() != end:
        distribution[bytes] = distribution.get(bytes, 0) + 1
        f.seek(1-n, 1)
        bytes = f.read(n)

print(distribution)
#if output is None:
    #print(json.dumps(distribution))
#else:
    #json.dump(distribution, open(output, "w"))

def n-gram(f, n):
    # This function will take a file-like object f and an integer n and run an
    # n-gram analysis on the contents of f. It will return a dictionary of
    # n-grams as the keys, with the values of each n-gram being the count of the
    # n-grams.
    pass

if __name__ == "__main__"
    # I like defining functions at the end, so we're using this so I can do that
    main()

#! /usr/bin/env python3

import argparse
import sys
import json

def main():
    parser = argparse.ArgumentParser(description="Create byte-wise n-gram distribution",)
    parser.add_argument('-n', default=1, help="Size of n-grams")
    parser.add_argument('-o', '--output', default=None, help="File to write output to")
    parser.add_argument('input', help="The file to be n-gram analyzed")

    args = parser.parse_args()

    file_name = args.input
    n = int(args.n)
    output = args.output

    distribution = dict()

    with open(file_name, "rb") as f:
        f.seek(0,2)
        end = f.tell()
        f.seek(0)
        bytes = f.read(n)
        while f.tell() != end:
            distribution[bytes] = distribution.get(bytes, 0) + 1
            f.seek(1-n, 1)
            bytes = f.read(n)

    print(distribution)
    #if output is None:
        #print(json.dumps(distribution))
    #else:
    #json.dump(distribution, open(output, "w"))

def n_gram(f, n):
    # This function will take a file-like object f and an integer n and run an
    # n-gram analysis on the contents of f. It will return a dictionary of
    # n-grams as the keys, with the values of each n-gram being the count of the
    # n-grams.
    pass

if __name__ == "__main__":
    # I like defining functions at the end, so we're using this so I can do that
    main()

Change n-grams-bytes to have a main function called correctly so it can also be used as a module