Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Jun 18, 2010 #1
    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?
  2. jcsd
  3. Jun 18, 2010 #2
    Oh yeah, and the code in this case looks something like this:
  4. Jun 18, 2010 #3


    Staff: Mentor

    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.
  5. Jun 18, 2010 #4
  6. Jun 18, 2010 #5


    User Avatar
    Homework Helper

    A "doc" file has binary information in as well as text. You should retry your program with a .txt file.
  7. Jun 18, 2010 #6
    Ah. That seems to have done it. Thank you.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook