code.Utils
1import math 2import re 3import sys 4import random 5import Num 6 7help = " \n\ 8CSV : summarized csv file \n\ 9(c) 2022 Tim Menzies <timm@ieee.org> BSD-2 license\n\ 10USAGE: lua seen.lua [OPTIONS]\n\ 11OPTIONS:\n\ 12-e --eg start-up example = nothing\n\ 13-d --dump on test failure, exit with stack dump = false\n\ 14-f --file file with csv data = ../data/auto93.csv\n\ 15-h --help show help = false\n\ 16-n --nums number of nums to keep = 512\n\ 17-s --seed random number seed = 10019\n\ 18-S --seperator feild seperator = , " 19 20def coerce(s): 21 s = s.strip() 22 if isinstance(s, int): 23 return int(s) 24 else: 25 try: 26 return float(s) 27 except ValueError: 28 if s in ['true', 'TRUE', 'True']: 29 return True 30 elif s in ['false', 'FALSE', 'False']: 31 return False 32 33def oo(t): 34 if isinstance(t, list): 35 out = "{" + " ".join(t)[:-1] + "}" 36 elif isinstance(t, dict): 37 out = o(t) 38 else: 39 dict_obj = vars(t) 40 del dict_obj['_has'] 41 out = (o(vars(t))) 42 print(out) 43 return out 44 45def o(t): 46 out = "{" 47 for k,v in t.items(): 48 out += ":" + str(k) + " " + str(v) + " " 49 out = out.strip() 50 out += "}" 51 return out 52 53def parse_csv(fname, fun=None, sep=','): 54 with open(fname, "r") as csv_file: 55 csv_file = csv_file.readlines() 56 for line in csv_file: 57 row = line.split(sep) 58 if fun: 59 fun(row) 60 61def copy(t): 62 if type(t) != dict: 63 return t 64 u = {} 65 for k, v in t.items(): 66 u[k] = copy(v) 67 return u 68 69def create_the(): 70 the = {} 71 tup_list = re.findall(r'[-][\S]+[\s]+[-][-]([\S]+)[^\n]+= ([\S]+)', help) 72 73 for k,x in tup_list: 74 the[k] = coerce(x) 75 return the 76 77the = create_the()
def
coerce(s):
def
oo(t):
def
o(t):
def
parse_csv(fname, fun=None, sep=','):
def
copy(t):
def
create_the():