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

Function create_file

Lib/test/test_shutil.py:71–82  ·  view source on GitHub ↗

Write *content* to a file located at *path*. If *path* is a tuple instead of a string, os.path.join will be used to make a path.

(path, content=b'')

Source from the content-addressed store, hash-verified

69 return wrap
70
71def create_file(path, content=b''):
72 """Write *content* to a file located at *path*.
73
74 If *path* is a tuple instead of a string, os.path.join will be used to
75 make a path.
76 """
77 if isinstance(path, tuple):
78 path = os.path.join(*path)
79 if isinstance(content, str):
80 content = content.encode()
81 with open(path, 'xb') as fp:
82 fp.write(content)
83
84def write_test_file(path, size):
85 """Create a test file with an arbitrary size and random text content."""

Calls 4

openFunction · 0.50
joinMethod · 0.45
encodeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…