def prefilter_PQ(self, line, continuation):
    """Alternate prefilter for input of PhysicalQuantityInteractive objects.

    This assumes that the function PhysicalQuantityInteractive() has been
    imported."""

    from re import match
    from IPython.core.iplib import InteractiveShell

    # This regexp is what does the real work
    unit_split = match(
        r'\s*(\w+)\s*=\s*(-?\d*\.?\d*[eE]?-?\d*)\s+([a-zA-Z].*)', line)

    # If special input was ecnountered, process it:
    if unit_split:
        var, val, units = unit_split.groups()
        if var and val and units:
            units = units.replace('^', '**')
            # Now a valid line needs to be constructed for IPython to process:
            line = var +" = PhysicalQuantityInteractive(" + val + ", '" + \
                   units + "')"
            #print 'New line:',line   # dbg

    # In the end, always call the default IPython _prefilter() function.  Note
    # that self must be passed explicitly, b/c we're calling the unbound class
    # method (since this method will overwrite the instance prefilter())
    return InteractiveShell._prefilter(self, line, continuation)
Example #2
0
def prefilter_PQ(self,line,continuation):
    """Alternate prefilter for input of PhysicalQuantityInteractive objects.

    This assumes that the function PhysicalQuantityInteractive() has been
    imported."""

    from re import match
    from IPython.core.iplib import InteractiveShell

    # This regexp is what does the real work
    unit_split = match(r'\s*(\w+)\s*=\s*(-?\d*\.?\d*[eE]?-?\d*)\s+([a-zA-Z].*)',
                       line)

    # If special input was ecnountered, process it:
    if unit_split:
        var,val,units = unit_split.groups()
        if var and val and units:
            units = units.replace('^','**')
            # Now a valid line needs to be constructed for IPython to process:
            line = var +" = PhysicalQuantityInteractive(" + val + ", '" + \
                   units + "')"
            #print 'New line:',line   # dbg
            
    # In the end, always call the default IPython _prefilter() function.  Note
    # that self must be passed explicitly, b/c we're calling the unbound class
    # method (since this method will overwrite the instance prefilter())
    return InteractiveShell._prefilter(self,line,continuation)