diff options
Diffstat (limited to 'tensorflow/python/platform/default/_resource_loader.py')
-rw-r--r-- | tensorflow/python/platform/default/_resource_loader.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tensorflow/python/platform/default/_resource_loader.py b/tensorflow/python/platform/default/_resource_loader.py new file mode 100644 index 0000000000..69f425072f --- /dev/null +++ b/tensorflow/python/platform/default/_resource_loader.py @@ -0,0 +1,26 @@ +"""Read a file and return its contents.""" + +import os.path + +from tensorflow.python.platform import logging + + +def load_resource(path): + """Load the resource at given path, where path is relative to tensorflow/. + + Args: + path: a string resource path relative to tensorflow/. + + Returns: + The contents of that resource. + + Raises: + IOError: If the path is not found, or the resource can't be opened. + """ + path = os.path.join('tensorflow', path) + path = os.path.abspath(path) + try: + with open(path, 'rb') as f: + return f.read() + except IOError as e: + logging.warning('IOError %s on path %s' % (e, path)) |