Chris Mutel  committed e5f6cf0

Query: Add Dictionaries class and make Filter arguments more sensical

  • Participants
  • Parent commits 5da5337

Comments (0)

Files changed (1)

File brightway2/

 # -*- coding: utf-8 -*
 import collections
 import operator
+import itertools
 operators = {
         return False
+class Dictionaries(object):
+    """A wrapper for a single call to iteritems() for multiple dictionaries.
+    Useful for a ``Query`` across multiple databases."""
+    def __init__(self, *args):
+        self.dicts = args
+    def iteritems(self):
+        return itertools.chain(*[x.iteritems() for x in self.dicts])
 class Result(object):
     """A container that wraps a filtered dataset. Returned by a calling a ``Query`` object. A result object functions like a read-only dictionary; you can call ``Result[some_key]``, or ``some_key in Result``, or ``len(Result)``.
 class Filter(object):
-    def __init__(self, key, value, function):
+    def __init__(self, key, function, value):
         self.key = key
+        self.function = function
         self.value = value
-        self.function = function
         if not callable(function):
             self.function = operators.get(function, None)
         if not self.function: