Skip to content

Instantly share code, notes, and snippets.

import pathlib
import argparse
def find_all_files(path: pathlib.Path, extension: str):
found_files = []
for f in path.glob(f"**/*{extension}"):
found_files.append(f)
return found_files
@mertzjames
mertzjames / var_length.py
Created February 27, 2020 23:12
Python Variabe Name Length
from random import randint
def create_and_verify_var(length):
"""Creates a variable with variable length of length, sets it to a
random integer and checks that that variable was indeed created and
correctly stores the integer"""
var_name = 'a' * length
expected_val = randint(0, 1000)
exec(f'{var_name} = {expected_val}')
@mertzjames
mertzjames / bltinmodule.c
Created November 18, 2015 15:57
Min function of python 3.5
# Note that the following is found in bltinmodule.c and is NOT the complete file.
static PyObject *
min_max(PyObject *args, PyObject *kwds, int op)
{
PyObject *v, *it, *item, *val, *maxitem, *maxval, *keyfunc=NULL;
PyObject *emptytuple, *defaultval = NULL;
static char *kwlist[] = {"key", "default", NULL};
const char *name = op == Py_LT ? "min" : "max";
const int positional = PyTuple_Size(args) > 1;