Re: Adding code and methods to a class dynamically
- From: Peter Hansen <peter@xxxxxxxxxxx>
- Date: Thu, 28 Jul 2005 21:54:10 -0400
Sarir Khamsi wrote:
Thanks, this is amazingly more simple than what I had. This works fine but I'm looking at the code for cmd and don't really see how you get completion to work on the new alias.
I'm not sure what "completion" means in this case, and I'm not aware of any "command-line completion" support in cmd.Cmd though it may well be there, so I can't say. Certainly there is nothing in any way different about the new attribute created by the alias code, as both it and the original attribute are bound to exactly the same method.
Also, I would like the alias to have arguments: alias newName existingName arg1 arg2 ...
Currying comes to mind, but I haven't tried it yet. Thanks again for the help.
It sounds like currying, but I'd suggest implementing such a thing with a completely separate layer on top of the existing Cmd stuff, probably through overriding .default() and doing a lookup in a dictionary, then building a command line with the original command and maybe executing it with .onecmd() if that can work from within the .cmdloop(). Lots of possibilities there; haven't tried any myself.
-Peter .
- References:
- Adding code and methods to a class dynamically
- From: Sarir Khamsi
- Re: Adding code and methods to a class dynamically
- From: Peter Hansen
- Re: Adding code and methods to a class dynamically
- From: Sarir Khamsi
- Adding code and methods to a class dynamically
- Prev by Date: Re: can list comprehensions replace map?
- Next by Date: Re: monitor a folder for file creation, how?
- Previous by thread: Re: Adding code and methods to a class dynamically
- Next by thread: Determine if object is a Bound or Unbound method
- Index(es):
Relevant Pages
|