livestock3d / livestock

Livestock is a package for Grasshopper providing components for modelling water movement and hydrothermal effects around buildings to enable and evaluate sustainable solutions, where those effects are incorporated.
GNU General Public License v3.0
9 stars 2 forks source link

Decorators for controlling inputs #2

Closed ocni-dtu closed 5 years ago

ocni-dtu commented 6 years ago

Create a decorator that will read a functions inputs from a file and hand it to the function

ocni-dtu commented 6 years ago

import numpy as np from functools import wraps import os

def file_asinput(function):

@wraps(function_)
def wrapper(*args, **kwargs):

    args_ = []
    for arg in args:
        try:
            os.path.isfile(arg)
            args_.append(np.loadtxt(arg))
        except ValueError:
            args_.append(arg)

    return function_(*args_, **kwargs)
return wrapper