Is it bad practice to use python's getattr extensively?
Posted
by Wilduck
on Stack Overflow
See other posts from Stack Overflow
or by Wilduck
Published on 2010-05-26T00:21:50Z
Indexed on
2010/05/26
0:31 UTC
Read the original article
Hit count: 259
I'm creating a shell-like environment. My original method of handleing user input was to use a dictionary mapping commands (strings) to methods of various classes, making use of the fact that functions are first class objects in python.
For flexibility's sake (mostly for parsing commands), I'm thinking of changing my setup such that I'm using getattr(command), to grab the method I need and then passing arguments to it at the end of my parser. Another advantage of this approach is not having to update my (currently statically implemented) command dictionary every time I add a new method/command.
My question is, will I be taking a hit to the efficiency of my shell? Does it matter how many methods/commands I have? I'm currently looking at 30 some commands, which could eventually double.
© Stack Overflow or respective owner