D
dubux
here is a function i wrote that doesnt work. i wrote to parse a "news"
file that is going to work in conjunction with a website via mod_wsgi.
my head hurts from looking at it so long. please help! i will further
explain in the post.
def news(x,y):
# usage news(date, number)
# x = date/news
# y = number
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, filter(lambda i: i%2 == 0, range
(len(news_list))))
date = mylist[y]
return '<center>%s</center><br>' % (date)
if x == 'news':
mylist = map(lambda i: news_list, filter(lambda i: i%2 == 1, range
(len(news_list))))
news = mylist[y]
return '%s<br>' % (news)
else:
return news_list
and call it with the follow syntax: news('[date/news]', [any number])
i keep getting "TypeError: list indices must be integers" on the
following line "date = mylist[y]"
can someone please explain this and give me the proper way to achieve
what im trying to do?
file that is going to work in conjunction with a website via mod_wsgi.
my head hurts from looking at it so long. please help! i will further
explain in the post.
def news(x,y):
# usage news(date, number)
# x = date/news
# y = number
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, filter(lambda i: i%2 == 0, range
(len(news_list))))
date = mylist[y]
return '<center>%s</center><br>' % (date)
if x == 'news':
mylist = map(lambda i: news_list, filter(lambda i: i%2 == 1, range
(len(news_list))))
news = mylist[y]
return '%s<br>' % (news)
else:
return news_list
and call it with the follow syntax: news('[date/news]', [any number])
i keep getting "TypeError: list indices must be integers" on the
following line "date = mylist[y]"
can someone please explain this and give me the proper way to achieve
what im trying to do?