Re: Adding code and methods to a class dynamically



Peter Hansen <peter@xxxxxxxxxxx> writes:

> If it's truly just an alias you want, then something like this should
> work better. Replace everything in the if mo: section with this:
>
> if mo:
> newName = mo.group(1)
> existingName = mo.group(2)
> existingMethod = getattr(self, 'do_' + existingName)
> setattr(self, 'do_' + newName, existingMethod)

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.

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.

Sarir
.



Relevant Pages