string to object?

Guy Robinson guy at NOSPAM.r-e-d.co.nz
Fri Jun 11 15:34:47 CEST 2004


Hello,

I have a class:

class foo:

	def method1(self,args):
		return 'one'
	def method2(self):
		return 'two'

and I have a series of strings li = ['foo.method1','foo.method2']

is there anyway I can do this?:

for l in li:
	print l(args)

getattr('foo','method1') didn't work as 'foo' is invalid.

Any suggestions appreciated.

Guy



More information about the Python-list mailing list