[IPython-user] notes and suggestions

r holland rhh at structurelabs.com
Mon Feb 20 21:39:44 CST 2006


In the online manual the usage for save is listed as

Usage:
%save filename n1-n2 n3-n4 ... n5 .. n6 ...

where it should be

Usage:
%save filename n1:n2 n3:n4 ... n5 .. n6 ...

  
A useful magic function is the clip function, which copies a set of 
input lines to the clipboard. To use this on Windows the win32clipboard 
module needs to be imported into the Magic.py module and the following 
function, based on the magic save function, needs to be added.

def magic_clip(self,parameter_s = ''):
        """Save a set of lines to the clipboard.

        Usage:\\
          %clip n1:n2 n3:n4 ... n5 .. n6 ...

        This function uses the same syntax as %macro for line 
extraction, but
        instead of creating a macro it saves the resulting string to the
        clipboard."""

        args = parameter_s.split()
        ranges = args[0:]
        cmds = ''.join(self.extract_input_slices(ranges))
        win32clipboard.OpenClipboard()
        win32clipboard.EmptyClipboard()
        win32clipboard.SetClipboardText(cmds)
        win32clipboard.CloseClipboard()
        print 'The following commands were written to the clipboard'
        print cmds

Rod Holland




More information about the IPython-user mailing list