Forums

New learner trying to open a file

I'm having trouble getting a file to open. I think I've got the absolute file path right, but instead of printing I get this: <_io.TextIOWrapper name='/home/RustyShankilford/mbox-short.txt' mode='r' encoding='UTF-8'>

I've reduced my code to just this and its still won't work:

fhand = open('/home/RustyShankilford/mbox-short.txt')
print(fhand)

How do I get python to print the file? I think I'm taking crazy pills.

You are printing the file object, not the content of the file. You need to print fhand.read() to see the content.

Thanks!

No problem