The Artima Developer Community
Sponsored Link

Python Buzz Forum
to throw, definitely

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
maxim khesin

Posts: 251
Nickname: xamdam
Registered: Mar, 2005

Maxim Khesin is developer for Liquidnet. I like C++, python, attend design patterns study group/NYC.
to throw, definitely Posted: Mar 2, 2005 7:36 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by maxim khesin.
Original Post: to throw, definitely
Feed Title: python and the web
Feed URL: http://feeds.feedburner.com/PythonAndTheWeb
Feed Description: blog dedicated to python and the networks we live in
Latest Python Buzz Posts
Latest Python Buzz Posts by maxim khesin
Latest Posts From python and the web

Advertisement
So Jeremy (my intro here) replied to my RFC. It appears putting a try-catch with an agreed-upon exception right into the bfs is a cool idea. So basically we would have something like
class traversal_termination_exception:pass

def bfs(graph, start, visitor):
try:
# actual bfs here
except traversal_termination_exception:
pass # this is a normal termination, nothin' to do

I was thinking that once we got to this point, we could take the next step: return a value from bfs. Why would we need this? Say our we want to search for the Bacon Number between Charlie Chaplin and Britney Spears. The result of this operation is a distance number, stored away in the visitor class. Since we decided to terminate the traversal with an exception when we reach Britney, why not stash the return value in the exception? With a little change, we have this:

class traversal_termination_exception:
def __init__(self, val = None):
self.val = val
def get_val(self):
return self.val

def bfs(graph, start, visitor):
try:
# actual bfs here
except traversal_termination_exception, e:
return e.get_val()
return None # for consistency?

What do ya think?


my recommended feed
my main blog here

Read: to throw, definitely

Topic: The good, the bad and the ugly Previous Topic   Next Topic Topic: announcing ua-devtalk

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use