Dennis Lee Bieber wrote:
> On Fri, 19 May 2006 14:41:13 +, [EMAIL PROTECTED] (Cameron Laird)
> declaimed the following in comp.lang.python: .
> > Guys, I try--I try *hard*--to accept the BetterToAskForgiveness
> > gospel, but this situation illustrates the discomfort I consistently
> >
Fredrik Lundh wrote:
> Cameron Laird wrote:
>
> > Guys, I try--I try *hard*--to accept the BetterToAskForgiveness
> > gospel, but this situation illustrates the discomfort I consistently
> > feel: how do I know that the NameError means VARIABLE didn't resolve,
> > rather than that it did, but that
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
[Cameron]
> try:
> getattr(commands, VARIABLE)()
> except NameError:
> print >> sys.stderr, "Unknown command", VARIABLE
>
> this situation illustrates the discomfort I consistently
> feel: how do I know that the NameError means VARIABLE didn't resolve,
> rather than that it did, but that
Cameron Laird wrote:
> Guys, I try--I try *hard*--to accept the BetterToAskForgiveness
> gospel, but this situation illustrates the discomfort I consistently
> feel: how do I know that the NameError means VARIABLE didn't resolve,
> rather than that it did, but that evaluation of commands.VARIABLE
In article <[EMAIL PROTECTED]>,
Grant Edwards <[EMAIL PROTECTED]> wrote:
>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, "Unkn
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
Hi all!
this is a (relatively) newbie question
I am writing a shell in Python and I am facing a problem
The problem is, after taking the input from user, i have to execute the
command which is a python function
i invoke an 'ls' command like this
commands.ls()
where commands.py is a fil
11 matches
Mail list logo