I have a simple qustion related opening file in Python.
Doing something like this:
x = open('test.txt', 'rt')
print(x)
I obtain this output:
<_io.TextIOWrapper name='test.txt' mode='rt' encoding='cp1252'>
that is the Python object representing the opened file. Is it considerable a stream or not? What exactly represents a stream in Python?
According to official documents of python 3, it is a stream.
The easiest way to create a text stream is with open(), optionally specifying an encoding:
f = open("myfile.txt", "r", encoding="utf-8")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With