Python newbie with a problem writing files

limodou limodou at gmail.com
Sun Sep 3 21:09:40 EDT 2006


On 9/4/06, John Jones <j4jones at ptd.net> wrote:
> 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)

Maybe there is a extra '=', if it should be:

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
>

-- 
I like python!
My Blog: http://www.donews.net/limodou
UliPad Site: http://wiki.woodpecker.org.cn/moin/UliPad
UliPad Maillist: http://groups.google.com/group/ulipad



More information about the Python-list mailing list