ID EN
IO

StringIO

Python 3.11 🇮🇩 Bahasa Indonesia

Aliran teks menggunakan buffer teks dalam memori. Ini mewarisi dari TextIOBase.

Syntax

PYTHON
class io.StringIO(initial_value='', newline='\n')

Contoh

Example 1
PYTHON
import io

output = io.StringIO()
output.write('First line.\n')
print('Second line.', file=output)

 Retrieve file contents -- this will be
 'First line.\nSecond line.\n'
contents = output.getvalue()

 Close object and discard memory buffer --
 .getvalue() will now raise an exception.
output.close()

See Also

TextIOBase close() write() TextIOWrapper StringIO TextIOBase IOBase str