In PS5 when i start the ps5.py file and press F5 to open the shell i get this thing "Unhandled exception in thread started by
Does this thing happen when you start other code? If not, can you post your code, please. Something raises an exception and there's no handler for it in the code.
its kinda long code bit here it is and this happens only when i run this code.. import feedparser import string import time from project_util import translate_html from news_gui import Popup #----------------------------------------------------------------------- # # Problem Set 5 #====================== # Code for retrieving and parsing # Google and Yahoo News feeds # Do not change this code #====================== def process(url): """ Fetches news items from the rss url and parses them. Returns a list of NewsStory-s. """ feed = feedparser.parse(url) entries = feed.entries ret = [] for entry in entries: guid = entry.guid title = translate_html(entry.title) link = entry.link summary = translate_html(entry.summary) try: subject = translate_html(entry.tags[0]['term']) except AttributeError: subject = "" newsStory = NewsStory(guid, title, subject, summary, link) ret.append(newsStory) return ret #====================== # Part 1 # Data structure design #====================== # Problem 1 # TODO: NewsStory #====================== # Part 2 # Triggers #====================== class Trigger(object): def evaluate(self, story): """ Returns True if an alert should be generated for the given news item, or False otherwise. """ raise NotImplementedError # Whole Word Triggers # Problems 2-5 # TODO: WordTrigger # TODO: TitleTrigger # TODO: SubjectTrigger # TODO: SummaryTrigger # Composite Triggers # Problems 6-8 # TODO: NotTrigger # TODO: AndTrigger # TODO: OrTrigger # Phrase Trigger # Question 9 # TODO: PhraseTrigger #====================== # Part 3 # Filtering #====================== def filter_stories(stories, triggerlist): """ Takes in a list of NewsStory-s. Returns only those stories for whom a trigger in triggerlist fires. """ # TODO: Problem 10 # This is a placeholder (we're just returning all the stories, with no filtering) # Feel free to change this line! return stories #====================== # Part 4 # User-Specified Triggers #====================== def readTriggerConfig(filename): """ Returns a list of trigger objects that correspond to the rules set in the file filename """ # Here's some code that we give you # to read in the file and eliminate # blank lines and comments triggerfile = open(filename, "r") all = [ line.rstrip() for line in triggerfile.readlines() ] lines = [] for line in all: if len(line) == 0 or line[0] == '#': continue lines.append(line) # TODO: Problem 11 # 'lines' has a list of lines you need to parse # Build a set of triggers from it and # return the appropriate ones import thread def main_thread(p): # A sample trigger list - you'll replace # this with something more configurable in Problem 11 t1 = SubjectTrigger("Obama") t2 = SummaryTrigger("MIT") t3 = PhraseTrigger("Supreme Court") t4 = OrTrigger(t2, t3) triggerlist = [t1, t4] # TODO: Problem 11 # After implementing readTriggerConfig, uncomment this line #triggerlist = readTriggerConfig("triggers.txt") guidShown = [] while True: print "Polling..." # Get stories from Google's Top Stories RSS news feed stories = process(" http://news.google.com/?output=rss ") # Get stories from Yahoo's Top Stories RSS news feed stories.extend(process(" http://rss.news.yahoo.com/rss/topstories ")) # Only select stories we're interested in stories = filter_stories(stories, triggerlist) # Don't print a story if we have already printed it before newstories = [] for story in stories: if story.get_guid() not in guidShown: newstories.append(story) for story in newstories: guidShown.append(story.get_guid()) p.newWindow(story) print "Sleeping..." time.sleep(SLEEPTIME) SLEEPTIME = 60 #seconds -- how often we poll if __name__ == '__main__': p = Popup() thread.start_new_thread(main_thread, (p,)) p.start()
and if I interrupt the problem i get this error ..: Traceback (most recent call last): File "C:\Users\CIM\Desktop\MIT Courses\6-00sc-spring-2011\6-00sc-spring-2011\contents\unit-2\ps5\ps5\ps5.py", line 175, in <module> p.start() File "C:\Users\CIM\Desktop\MIT Courses\6-00sc-spring-2011\6-00sc-spring-2011\contents\unit-2\ps5\ps5\news_gui.py", line 21, in start self.root.mainloop() File "D:\Python27\lib\lib-tk\Tkinter.py", line 1017, in mainloop self.tk.mainloop(n) KeyboardInterrupt
Have you tried actually reading the problem set instructions and implementing some code?
well, the KeyboardInterrupt raised by self.tk.mainloop(n) in file Tkinter.py is not handled you import code from news_gui.py and from Tkinter.py
you may consider switching debugger on in IDLE and see how the code is executed step by step
Join our real-time social learning platform and learn together with your friends!