def maybe_save(resource_id, path,
               code=None, location=None,
               resource=None, error=None):
    """Builds the resource dict response and saves it if a path is provided.

    The resource is saved in a local repo json file in the given path.

    """
    resource = resource_structure(code, resource_id, location, resource, error)

    if path is not None and resource_id is not None:
        try:
            resource_json = json.dumps(resource)
        except __HOLE__:
            print "The resource has an invalid JSON format"
        try:
            resource_file_name = "%s%s%s" % (path, os.sep,
                                             resource_id.replace('/', '_'))
            with open(resource_file_name, "wb", 0) as resource_file:
                resource_file.write(resource_json.encode('UTF-8'))
        except IOError:
            print "Failed writing resource to %s" % resource_file_name
    return resource
dataset/ETHPy150Open bigmlcom/python/bigml/util.py/maybe_save