File Reading In Mac

Discussion in 'Python' started by dilip raghavan, Nov 23, 2010.

  1. Hello ,
    I have been trying to read contents from a file in MAC.
    I wrote the code

    filename = "test.rtf"
    FileHandle = open(filename,'r')

    fileStr = FileHandle.read()
    print fileStr
    FileHandle.close()

    When I see the output I see a lot of junk. The junk is like a lot of
    question marks, the font information and other details of the file.
    The actual content is lost in the junk.

    I have tried other methods like readline but still I see the junk.
    I tried the asme code in windows and it worked correctly.
    Can any one tell me the reason and the solution for this.

    Thanks In advance.
     
    dilip raghavan, Nov 23, 2010
    #1
    1. Advertising

  2. dilip raghavan

    Ned Deily Guest

    In article
    <>,
    dilip raghavan <> wrote:
    > I have been trying to read contents from a file in MAC.
    > I wrote the code
    >
    > filename = "test.rtf"
    > FileHandle = open(filename,'r')
    >
    > fileStr = FileHandle.read()
    > print fileStr
    > FileHandle.close()
    >
    > When I see the output I see a lot of junk. The junk is like a lot of
    > question marks, the font information and other details of the file.
    > The actual content is lost in the junk.
    >
    > I have tried other methods like readline but still I see the junk.
    > I tried the asme code in windows and it worked correctly.
    > Can any one tell me the reason and the solution for this.


    With an extension of "rtf", the file is presumably a "Rich Text Format"
    file. http://en.wikipedia.org/wiki/Rich_Text_Format

    There are some Python packages out there for dealing with rtf format
    files. You might try rtf2xml to convert the file, preserving style
    attributes: http://pypi.python.org/pypi/rtf2xml/
    Or look at the Mac OS X command line utility textutil (man 1 textutil)
    to convert the file to another format. Or use the OS X TextEdit.app.

    --
    Ned Deily,
     
    Ned Deily, Nov 23, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roman =?ISO-8859-15?Q?Bl=F6th?=

    Senseless rendering: Mac.Mozilla != Mac.Netscape6.01 ?!?!

    Roman =?ISO-8859-15?Q?Bl=F6th?=, Jul 2, 2003, in forum: HTML
    Replies:
    1
    Views:
    1,000
    Steve Pugh
    Jul 2, 2003
  2. mangm
    Replies:
    2
    Views:
    748
    mangm
    Dec 1, 2005
  3. jennyw
    Replies:
    0
    Views:
    320
    jennyw
    Jul 11, 2003
  4. Skip Montanaro
    Replies:
    0
    Views:
    429
    Skip Montanaro
    Jul 11, 2003
  5. Franck Ditter

    Reading a file in IDLE 3 on Mac-Lion

    Franck Ditter, Sep 21, 2012, in forum: Python
    Replies:
    6
    Views:
    282
    Kevin Walzer
    Sep 23, 2012
Loading...

Share This Page