best way to parse a function-call-like string?

mh at pixar.com mh at pixar.com
Thu Feb 26 16:29:19 EST 2009


I have some strings that look like function calls, e.g.

	"junkpkg.f1"
	"junkpkg.f1()"
	"junkpkg.f1('aaa')"
	"junkpkg.f1('aaa','bbb')"
	"junkpkg.f1('aaa','bbb','ccc')"
	"junkpkg.f1('aaa','with,comma')"

and I need to split them into the function name and list of parms, e.g.

	"junkpkg.f1", []
	"junkpkg.f1", []
	"junkpkg.f1", ['aaa']
	"junkpkg.f1", ['aaa','bbb']
	"junkpkg.f1", ['aaa','bbb','ccc']
	"junkpkg.f1", ['aaa','with,comma']

What's the best way to do this?  I would be interested in either
of two approaches:

   - a "real" way which comprehensively

   - a quick-and-dirty way which handles most cases, so that I
     can get my coding partner running quickly while I do the
     "real" way.  will the csv module do the right thing for
     the parm list?

Many TIA!!
Mark




-- 
Mark Harrison
Pixar Animation Studios



More information about the Python-list mailing list