Python newbie with a problem writing files

J

John Jones

Hi All,

I have been driven insane by this error. I have this small program, shown below, which runs great until it gets to writing the data out to the file. I am running an install of Python 2.4. Yes, feedparser is functioning fine (I put in print feed_title statements as tests - but have since removed them). I am missing something obvious.

Thanks
JJ

Code:

import feedparser
from xml.sax import saxutils

feed_number=200

feed_list = open("feed_listing.conf","r")
for each_feed in feed_list:
data=feedparser.parse(each_feed)
feed_title=data.entries[0].title
xml_output=open("xml_data\\feed" + str(feed_number) + ".xml", "w")
xml_output.write = (feed_title)
xml_output.close()
feed_number+=1

Error Message:

Traceback (most recent call last):
File "C:/My_Blogroll/JJ_Blogroll2", line 11, in ?
xml_output.write = (feed_title)
AttributeError: 'file' object attribute 'write' is read-only
 
T

Tim Chase

feed_list = open("feed_listing.conf","r")
What could it be about the above line that means "Open this file for
READ ONLY"?

Oooh, oooh, I know! If you rot13 the file-name, it comes back as
"srrq_yvfgvat.pbas". The double "r"s in the file-name instruct
python to open the file as "really read-only". And the .pbas
means you need to be opening the file with python-basic, not python.

:)

-tkc
 
J

John Machin

Mike said:
What could it be about the above line that means "Open this file for
READ ONLY"?

That's his *INPUT* file. The error referred to his *OUTPUT* file, and
in any case the complain was that the "write" attribute was read-only,
*NOT* the ferschlugginer file itself.

"Sheesh!" * 2
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top