TypeError: list indices must be integers

dubux wx1234 at gmail.com
Wed Dec 31 05:26:00 CET 2008


thanks for help everyone. it turned out the function itself worked
fine.. it was the way i was calling it that was messing everything up.
i ended up re-doing the whole thing as follows, and it now works
perfectly.

def news(x,y):
	news_file = '/home/scam/Desktop/www/info/news'
	news = open(news_file, 'r')
	news_list = news.readlines()
	news.close()
	if x == 'date':
		mylist = map(lambda i: news_list[i], filter(lambda i: i%2 == 0, range
(len(news_list))))
		date = mylist[y].replace("\n","")
		return '<center><p>%s</p></center>\n\n' % (date)
	if x == 'news':
		mylist = map(lambda i: news_list[i], filter(lambda i: i%2 == 1, range
(len(news_list))))
		news = mylist[y].replace("\n","")
		return '<center><p>%s</p></center>\n<br>\n' % (news)
	else:
		return news_list

news_parse, count, news_list = " ", 0, news('list','list')
newss = map(lambda i: news_list[i], filter(lambda i: i%2 == 1, range
(len(news_list))))
while count < len(newss):
	get_date = news('date', count)
	get_news = news('news', count)
	news_parse = '%s %s %s' % (news_parse, get_date, get_news)
	count = count + 1




More information about the Python-list mailing list