You can use Python in interactive mode to search for solutions.
if f
is your object, you can enter dir(f)
to see all methods and attributes. There’s one called read
. Enter help(f.read)
and it tells you that f.read()
is the way to retrieve a string from an file object.