[Python-ideas] multiple objects handling

Bruce Leban bruce at leapyear.org
Fri Aug 12 23:45:01 CEST 2011

On Fri, Aug 12, 2011 at 1:49 PM, Peter V. Saveliev <peet at altlinux.ru> wrote:

> I have a stream of objects, each of dictionary type....
> I shoud take an action depending on event's 'type' (neigh[bor], link,
> address, route etc.) and 'action' (add, del) items.
> Now I see two ways:
> * build a tree of <<if/elif>> statements within one function
> * create a dictionary that points to different methods
> The issue is that a method call is slower that jump within one function.

Is the overhead of a method call the biggest problem in your code?

> But a dictionary lookup is faster than <<if/elif>> statements (if I have a
> lot of variants and do not want to rebuild B-like tree of <<if>>
> statements by hands).
> Is there a way to combine these methods? Can I create a dictionary of
> jump instructions?

How would this be useful to someone writing a python program? Or put another
way, if the Python interpreter had such a feature, what language feature
would use it? Since there is no switch statement
http://www.python.org/dev/peps/pep-3103/ this seems premature optimization.

--- Bruce
Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110812/8382b0ed/attachment.html>

More information about the Python-ideas mailing list