>>> p.read_text()
'Text file contents'
+ Return the number of characters written.
+
An existing file of the same name is overwritten. The optional parameters
have the same meaning as in :func:`open`.
>>> p.read_bytes()
b'Binary file contents'
+ Return the number of bytes written.
+
An existing file of the same name is overwritten.
.. versionadded:: 3.5
def write_bytes(self, data):
"""
Open the file in bytes mode, write to it, and close the file.
+ Return the number of bytes written.
"""
# type-check for the buffer interface before truncating the file
view = memoryview(data)
def write_text(self, data, encoding=None, errors=None, newline=None):
"""
Open the file in text mode, write to it, and close the file.
+ Return the number of characters written.
"""
# Call io.text_encoding() here to ensure any warning is raised at an
# appropriate stack level.
def write_bytes(self, data):
"""
Open the file in bytes mode, write to it, and close the file.
+ Return the number of bytes written.
"""
# type-check for the buffer interface before truncating the file
view = memoryview(data)
def write_text(self, data, encoding=None, errors=None, newline=None):
"""
Open the file in text mode, write to it, and close the file.
+ Return the number of characters written.
"""
# Call io.text_encoding() here to ensure any warning is raised at an
# appropriate stack level.