MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / read_file_to_string

Function read_file_to_string

tensorflow/python/lib/io/file_io.py:314–333  ·  view source on GitHub ↗

Reads the entire contents of a file to a string. Args: filename: string, path to a file binary_mode: whether to open the file in binary mode or not. This changes the type of the object returned. Returns: contents of the file as a string or bytes. Raises: errors.OpError

(filename, binary_mode=False)

Source from the content-addressed store, hash-verified

312
313
314def read_file_to_string(filename, binary_mode=False):
315 """Reads the entire contents of a file to a string.
316
317 Args:
318 filename: string, path to a file
319 binary_mode: whether to open the file in binary mode or not. This changes
320 the type of the object returned.
321
322 Returns:
323 contents of the file as a string or bytes.
324
325 Raises:
326 errors.OpError: Raises variety of errors that are subtypes e.g.
327 NotFoundError etc.
328 """
329 if binary_mode:
330 f = FileIO(filename, mode="rb")
331 else:
332 f = FileIO(filename, mode="r")
333 return f.read()
334
335
336def write_string_to_file(filename, file_content):

Callers

nothing calls this directly

Calls 2

readMethod · 0.95
FileIOClass · 0.85

Tested by

no test coverage detected