MCPcopy Index your code
hub / github.com/python/cpython / read_file

Function read_file

Lib/test/test_shutil.py:102–114  ·  view source on GitHub ↗

Return contents from a file located at *path*. If *path* is a tuple instead of a string, os.path.join will be used to make a path. If *binary* is true, the file will be opened in binary mode.

(path, binary=False)

Source from the content-addressed store, hash-verified

100 assert os.path.getsize(path) == size
101
102def read_file(path, binary=False):
103 """Return contents from a file located at *path*.
104
105 If *path* is a tuple instead of a string, os.path.join will be used to
106 make a path. If *binary* is true, the file will be opened in binary
107 mode.
108 """
109 if isinstance(path, tuple):
110 path = os.path.join(*path)
111 mode = 'rb' if binary else 'r'
112 encoding = None if binary else "utf-8"
113 with open(path, mode, encoding=encoding) as fp:
114 return fp.read()
115
116def rlistdir(path):
117 res = []

Callers 13

test_copytree_simpleMethod · 0.85
test_copy_symlinksMethod · 0.85
test_copy2_symlinksMethod · 0.85
test_regular_copyMethod · 0.85
test_same_fileMethod · 0.85
test_empty_fileMethod · 0.85
test_cant_get_sizeMethod · 0.85
test_small_chunksMethod · 0.85

Calls 3

openFunction · 0.50
joinMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…