Why does the function file_object.readlines() return code and not text?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 3K views
zakbrown0308
Messages
13
Reaction score
0
Okay, I just began a bit of a python phase, and I want some help. You'll probably be hearing from me quite a bit in the next few weeks. Anyway, my question is about I/O functions. Specifically when it comes to opening and closing text documents. I have successfully opened a file (which I called file_object), and when I print the readlines() function, I get a bunch of code, not the text from my document. And yes, I did use seek() to place my cursor. So, any suggestions?
 
Physics news on Phys.org
Oh yeah, and the code in this case looks something like this:
ÐÏࡱ
 
Is the file you are opening a text file or a binary file? The output you show makes me think the file is a binary file.

It would be more helpful if you showed your code.
 
Specifically when it comes to opening and closing text documents.[/QUOTE said:
And oops! That was the wrong example. The code that *I* wrote looks like this:

opendoc = open ("theRaven.doc", "r")

opendoc.seek(0,0)

print opendoc.readlines ()



And the function returned a code like this:

['\xd0\xcf\x11\xe0\xa1\xb1']
 
Ah. That seems to have done it. Thank you.