bruno at modulix <[EMAIL PROTECTED]> writes:
> Ben Finney wrote:
> > You'll also need to anticipate the situation where the value bound
> > to VARIABLE is not the name of an attribute in 'commands'.
> >
> > Either deal with the resulting NameError exception (EAFP[0])
>
> try:
> getattr(command
On 2006-05-19, bruno at modulix <[EMAIL PROTECTED]> wrote:
>> Either deal with the resulting NameError exception (EAFP[0])
>
> try:
> getattr(commands, VARIABLE)()
> except NameError:
> print >> sys.stderr, "Unknown command", VARIABLE
>
>> or test
>> first whether the attribute exists (LBYL[1]
Ben Finney wrote:
> Peter Otten <[EMAIL PROTECTED]> writes:
(snip)
>>
>>You want
>>getattr(commands, VARIABLE)()
>
> You'll also need to anticipate the situation where the value bound to
> VARIABLE is not the name of an attribute in 'commands'.
>
> Either deal with the resulting NameError excepti
Peter Otten <[EMAIL PROTECTED]> writes:
> creo wrote:
> > what i want to do is
> > commands.VARIABLE()
> > where VARIABLE holds the name of the function which i want to execute
> > and depends on what the user has typed
>
> You want
>
> getattr(commands, VARIABLE)()
You'll also need to anticipa
creo wrote:
> i invoke an 'ls' command like this
> commands.ls()
> where commands.py is a file in the same directory
>
> what i want to do is
> commands.VARIABLE()
> where VARIABLE holds the name of the function which i want to execute
> and depends on what the user has typed
You want
getattr(c