
class dotdict(dict):
    __getattr__ = dict.get
    __setattr__ = dict.__setitem__
    __delattr__ = dict.__delitem__


def myparser(s):
    try:
        s = float(s)
    except:
        pass
    return s


def arg_split(args, split_str=','):
    """
    input: args, argparse.ArgumentParser().parse_args()
    output: list of float or str.
    samples:
    args.key=['1']
    arg_split(args).key = ['1']

    args.key=['1,4']
    arg_split(args).key = ['1','4']

    args.key=['a']
    arg_split(args).key = ['a']

    args.key=['a,b']
    arg_split(args).key = ['a','b']

    """
    new_args = dotdict()
    for arg in vars(args):
        if isinstance(getattr(args, arg), str):
            new_args[arg] = [myparser(item)
                             for item in getattr(args, arg).split(split_str)]
        else:
            new_args[arg] = [getattr(args, arg)]
        if len(new_args[arg]) == 1:
            new_args[arg] = new_args[arg][0]
    return new_args
