File Reading In Mac

D

dilip raghavan

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.
 
N

Ned Deily

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top