def consult(self, func):
        """
        Include definitions from func into database
        """
        try:
            code = func.func_code
        except:
            raise TypeError, "function or method argument expected"
        names = code.co_names
        locally_defined = code.co_varnames
        globally_defined = func.func_globals.keys()
        defined = locally_defined+tuple(globally_defined)
        # Python < 2.0
        # undefined = filter (lambda n,d=defined: n not in d, names)
        # Modern Python
        undefined = [name for name in names if name not in defined]
        # Generate the new global environment for the function;
        # to the old environment, add definitions for all undefined
        # symbols, which relate to this database (self). When the
        # symbols are operated on in the function, they will add
        # facts and conditionals to the database.
        newglobals = func.func_globals.copy()
        for name in undefined:
            newglobals[name] = symbol(name, self)
        exec code in newglobals

        Include definitions from func into database
        
recipes/Python/303057_Pythologic__Prolog_syntax/recipe-303057.py