I create a shell environment. My original method of handling user input was to use dictionary matching commands (strings) for methods of different classes, using the fact that functions are first class objects in python.
For more flexibility (mainly for parsing commands) I'm going to change my setting to use the getattr (command) command to grab the method I need and then pass arguments to it at the end of my parsing. Another advantage of this approach is the lack of having to update my (currently statically implemented) command dictionary every time I add a new method / command.
My question is double. First, does getattr have the same problems as eval? Secondly, will I hit the effectiveness of my shell? It doesn't matter how many methods / commands I have? I am currently scrolling through 30 teams that could double in the long run.
performance python shell getattr
Wilduck
source share