Circular reference problem -- advice?

jepler epler jepler.lnk at lnk.ispi.net
Wed Jul 12 08:34:23 EDT 2000


On Mon, 10 Jul 2000 22:20:24 -0700, Erik Max Francis
 <max at alcyone.com> wrote:
>It actually is necessary for my purposes, since the strings that is used
>for dispatching will not be a status code (a three digit number as a
>string), not actually the name of the method to be invoked.  (I simply
>showed it that way for the purposes of the sample code; certainly in the
>example I showed you are correct.)
>
>Thanks, though.

You can use a method like finding a method named '"code_%03d" % status':

class C:
	def dispatch(self, status, *args):
		g = getattr(self, "code_%03d" % status, None)
		if g:
			apply(g,args)
	def code_000(self, arg1, arg2):
		print "the args were", arg1, arg2

c=C()
c.dispatch(0, "hi mom", 36)  # -> "the args were hi mom 36"



More information about the Python-list mailing list