dynamic class/module use? (like Java's forName)

Paul McGuire ptmcg at austin.rr._bogus_.com
Sun Jul 18 07:00:33 CEST 2004


"Alex Hunsley" <lard at tardis.ed.ac.molar.uk> wrote in message
news:8glKc.31979$v7.20488 at fe2.news.blueyonder.co.uk...
<snip>
> Ok, the situation is that I am parsing a file that has "actions" (or
> commands) embedded in it. Different actions cause different things to
> happen to the file which is being preprocessed for something. Now, since
> I will have many actions, and want my python to be extensible so other
> users can add their own actions, rather than hard coding each action
> like so:
>
>   if (actionString == "blah"):
>       blahThang = blah(constructor stuff)
>       blahThang.doSomething()
>   else if (actionString == "blah2"):
>       blahThang2 = blah2(constructor stuff)
>       blahThang2.doSomething()
>   else if (actionString == "blah3"):
>       blahThang3 = blah3(constructor stuff)
>       blahThang3.doSomething()
>   else if (actionString == "blah2"):
>    # etc etc
<snip>

Alex,

Have a look at how pyparsing (http://pyparsing.sourceforge.net) supports the
attachment of actions to parse expressions within a grammar.

-- Paul





More information about the Python-list mailing list