Changeset 2871


Ignore:
Timestamp:
Jul 28, 2010 12:17:16 PM (9 years ago)
Author:
prsteel
Message:

functools module is not available in all versions of Python, namely 2.4. Define relevant function `partial' in the case of an import failure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/transform/nonnegative_transform.py

    r2869 r2871  
    11from inspect import isroutine
    2 from functools import partial
     2
     3try:
     4    from functools import partial
     5except ImportError:
     6    # functools doesn't exist in Python 2.4
     7    def partial(f, *args, **kwds):
     8        """
     9        Returns a new function with positional and keyword arguments
     10        partially applied
     11
     12        """
     13        args = list(args)
     14        def closure(*pargs, **pkwds):
     15            # Collect positional arguments
     16            args.extend(pargs)
     17
     18            # Update keyword arguments
     19            kwds.update(**pkwds)
     20
     21            # Call the original function
     22            return f(*args, **kwds)
     23        return closure
    324
    425from coopr.pyomo import *
Note: See TracChangeset for help on using the changeset viewer.