File Reading In Mac

Ned Deily nad at
Tue Nov 23 02:50:07 CET 2010

In article 
<66e4164c-e81d-4a65-b847-c5ef900fa14c at>,
 dilip raghavan <dilip1984me at> 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 =
> 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" 

There are some Python packages out there for dealing with rtf format 
files.  You might try rtf2xml to convert the file, preserving style 
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

 Ned Deily,
 nad at

More information about the Python-list mailing list