Changeset 3008
- Timestamp:
- 02/02/08 10:13:00 (10 months ago)
- Files:
-
- ipython/trunk/IPython/Extensions/ipipe.py (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ipython/trunk/IPython/Extensions/ipipe.py
r3000 r3008 7 7 8 8 ``ipipe`` supports "pipeline expressions", which is something resembling Unix 9 pipes. An example is: 9 pipes. An example is:: 10 10 11 11 >>> ienv | isort("key.lower()") … … 46 46 * Objects that can be iterated by ``Pipe``s must iterable. For special cases, 47 47 where iteration for display is different than the normal iteration a special 48 implementation can be registered with the generic function ``xiter``. This makes 49 it possible to use dictionaries and modules in pipeline expressions, for example: 48 implementation can be registered with the generic function ``xiter``. This 49 makes it possible to use dictionaries and modules in pipeline expressions, 50 for example:: 50 51 51 52 >>> import sys … … 62 63 Note: The expression strings passed to ``ifilter()`` and ``isort()`` can 63 64 refer to the object to be filtered or sorted via the variable ``_`` and to any 64 of the attributes of the object, i.e.: 65 of the attributes of the object, i.e.:: 65 66 66 67 >>> sys.modules | ifilter("_.value is not None") | isort("_.key.lower()") 67 68 68 does the same as 69 does the same as:: 69 70 70 71 >>> sys.modules | ifilter("value is not None") | isort("key.lower()") 71 72 72 73 In addition to expression strings, it's possible to pass callables (taking 73 the object as an argument) to ``ifilter()``, ``isort()`` and ``ieval()``: 74 the object as an argument) to ``ifilter()``, ``isort()`` and ``ieval()``:: 74 75 75 76 >>> sys | ifilter(lambda _:isinstance(_.value, int)) \ … … 640 641 the ``Display`` object will display ``item``: 641 642 642 * ``"header"``: ``item`` will be displayed in a header line (this is used by 643 ``ibrowse``). 644 * ``"footer"``: ``item`` will be displayed in a footer line (this is used by 645 ``ibrowse``). 646 * ``"cell"``: ``item`` will be displayed in a table cell/list. 647 * ``"default"``: default mode. If an ``xrepr`` implementation recursively 648 outputs objects, ``"default"`` must be passed in the recursive calls to 649 ``xrepr``. 643 ``"header"`` 644 ``item`` will be displayed in a header line (this is used by ``ibrowse``). 645 646 ``"footer"`` 647 ``item`` will be displayed in a footer line (this is used by ``ibrowse``). 648 649 ``"cell"`` 650 ``item`` will be displayed in a table cell/list. 651 652 ``"default"`` 653 default mode. If an ``xrepr`` implementation recursively outputs objects, 654 ``"default"`` must be passed in the recursive calls to ``xrepr``. 650 655 651 656 If no implementation is registered for ``item``, ``xrepr`` will try the … … 875 880 There are two possible modes: 876 881 877 * ``"detail"``: The ``Display`` object wants to display a detailed list 878 of the object attributes. 879 * ``"default"``: The ``Display`` object wants to display the object in a 880 list view. 882 ``"detail"`` 883 The ``Display`` object wants to display a detailed list of the object 884 attributes. 885 886 ``"default"`` 887 The ``Display`` object wants to display the object in a list view. 881 888 882 889 If no implementation is registered for the object ``item`` ``xattrs`` falls … … 1201 1208 List the current (or a specified) directory. 1202 1209 1203 Examples: 1210 Examples:: 1204 1211 1205 1212 >>> ils … … 1239 1246 (See ``glob.glob()`` for more info.). 1240 1247 1241 Examples: 1248 Examples:: 1242 1249 1243 1250 >>> iglob("*.py") … … 1264 1271 class iwalk(Table): 1265 1272 """ 1266 List all files and directories in a directory and it's subdirectory .1273 List all files and directories in a directory and it's subdirectory:: 1267 1274 1268 1275 >>> iwalk … … 1369 1376 List all entries in the Unix user account and password database. 1370 1377 1371 Example: 1378 Example:: 1372 1379 1373 1380 >>> ipwd | isort("uid") … … 1553 1560 List environment variables. 1554 1561 1555 Example: 1562 Example:: 1556 1563 1557 1564 >>> ienv … … 1574 1581 IPython input history 1575 1582 1576 Example: 1583 Example:: 1577 1584 1578 1585 >>> ihist … … 1594 1601 class icsv(Pipe): 1595 1602 """ 1596 This ``Pipe`` lists turnthe input (with must be a pipe outputting lines1603 This ``Pipe`` turns the input (with must be a pipe outputting lines 1597 1604 or an ``ifile``) into lines of CVS columns. 1598 1605 """ … … 1643 1650 (similar to ``os.popen()``). 1644 1651 1645 Examples: 1652 Examples:: 1646 1653 1647 1654 >>> ix("ps x") … … 1682 1689 (and doesn't raise an exception) are listed. 1683 1690 1684 Examples: 1691 Examples:: 1685 1692 1686 1693 >>> ils | ifilter("_.isfile() and size>1000") … … 1697 1704 of ``expr`` are handled: 1698 1705 1699 * ``drop``: drop all items that have errors; 1700 1701 * ``keep``: keep all items that have errors; 1702 1703 * ``keeperror``: keep the exception of all items that have errors; 1704 1705 * ``raise``: raise the exception; 1706 1707 * ``raiseifallfail``: raise the first exception if all items have errors; 1708 otherwise drop those with errors (this is the default). 1706 ``"drop"`` 1707 drop all items that have errors; 1708 1709 ``"keep"`` 1710 keep all items that have errors; 1711 1712 ``"keeperror"`` 1713 keep the exception of all items that have errors; 1714 1715 ``"raise"`` 1716 raise the exception; 1717 1718 ``"raiseifallfail"`` 1719 raise the first exception if all items have errors; otherwise drop 1720 those with errors (this is the default). 1709 1721 """ 1710 1722 self.expr = expr … … 1769 1781 Evaluate an expression for each object in the input pipe. 1770 1782 1771 Examples: 1783 Examples:: 1772 1784 1773 1785 >>> ils | ieval("_.abspath()") … … 1841 1853 with ``index`` and ``object`` attributes). 1842 1854 1843 Examples: 1855 Examples:: 1844 1856 1845 1857 >>> xrange(20) | ieval("_,_*_") | ienum | ifilter("index % 2 == 0") | ieval("object") … … 1855 1867 Sorts the input pipe. 1856 1868 1857 Examples: 1869 Examples:: 1858 1870 1859 1871 >>> ils | isort("size") … … 2013 2025 Execute a python string and capture any output to stderr/stdout. 2014 2026 2015 Examples: 2027 Examples:: 2016 2028 2017 2029 >>> import time
