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 exception (EAFP[0])
try:
getattr(commands, VARIABLE)()
except NameError:
print >> sys.stderr, "Unknown command", VARIABLE
> or test
> first whether the attribute exists (LBYL[1]).
command = getattr(commands, VARIABLE, None)
if command is None:
print >> sys.stderr, "Unknown command", VARIABLE
else:
command()
I'd go for the first solution.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
--
http://mail.python.org/mailman/listinfo/python-list