Show More
This diff has been collapsed as it changes many lines, (1322 lines changed) Show them Hide them | |||||
@@ -2,8 +2,8 b'' | |||||
2 | You can adapt this file completely to your liking, but it should at least |
|
2 | You can adapt this file completely to your liking, but it should at least | |
3 | contain the root 'toctree' directive. |
|
3 | contain the root 'toctree' directive. | |
4 |
|
4 | |||
5 |
|
|
5 | IPython documentation | |
6 |
===================== |
|
6 | ===================== | |
7 |
|
7 | |||
8 | Contents: |
|
8 | Contents: | |
9 |
|
9 | |||
@@ -1389,15 +1389,19 b' typing %magic at the prompt, but that will also give you information' | |||||
1389 | about magic commands you may have added as part of your personal |
|
1389 | about magic commands you may have added as part of your personal | |
1390 | customizations. |
|
1390 | customizations. | |
1391 |
|
1391 | |||
1392 | :: |
|
1392 | .. magic_start | |
1393 |
|
1393 | |||
1394 | %Exit: Exit IPython without confirmation. |
|
1394 | **%Exit**:: | |
1395 |
|
1395 | |||
|
1396 | Exit IPython without confirmation. | |||
1396 |
|
1397 | |||
1397 | %Pprint: Toggle pretty printing on/off. |
|
1398 | **%Pprint**:: | |
1398 |
|
1399 | |||
|
1400 | Toggle pretty printing on/off. | |||
1399 |
|
1401 | |||
1400 | %alias: Define an alias for a system command. |
|
1402 | **%alias**:: | |
|
1403 | ||||
|
1404 | Define an alias for a system command. | |||
1401 |
|
1405 | |||
1402 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' |
|
1406 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' | |
1403 |
|
1407 | |||
@@ -1405,41 +1409,41 b' customizations.' | |||||
1405 | params' (from your underlying operating system). |
|
1409 | params' (from your underlying operating system). | |
1406 |
|
1410 | |||
1407 | Aliases have lower precedence than magic functions and Python normal |
|
1411 | Aliases have lower precedence than magic functions and Python normal | |
1408 |
|
|
1412 | variables, so if 'foo' is both a Python variable and an alias, the | |
1409 |
|
|
1413 | alias can not be executed until 'del foo' removes the Python variable. | |
1410 |
|
1414 | |||
1411 | You can use the %l specifier in an alias definition to represent the |
|
1415 | You can use the %l specifier in an alias definition to represent the | |
1412 | whole line when the alias is called. For example: |
|
1416 | whole line when the alias is called. For example: | |
1413 |
|
1417 | |||
1414 |
|
|
1418 | In [2]: alias all echo "Input in brackets: <%l>"\ | |
1415 |
|
|
1419 | In [3]: all hello world\ | |
1416 | Input in brackets: <hello world> |
|
1420 | Input in brackets: <hello world> | |
1417 |
|
1421 | |||
1418 |
|
|
1422 | You can also define aliases with parameters using %s specifiers (one | |
1419 |
|
|
1423 | per parameter): | |
1420 |
|
1424 | |||
1421 |
|
|
1425 | In [1]: alias parts echo first %s second %s\ | |
1422 |
|
|
1426 | In [2]: %parts A B\ | |
1423 |
|
|
1427 | first A second B\ | |
1424 |
|
|
1428 | In [3]: %parts A\ | |
1425 |
|
|
1429 | Incorrect number of arguments: 2 expected.\ | |
1426 | parts is an alias to: 'echo first %s second %s' |
|
1430 | parts is an alias to: 'echo first %s second %s' | |
1427 |
|
1431 | |||
1428 |
|
|
1432 | Note that %l and %s are mutually exclusive. You can only use one or | |
1429 |
|
|
1433 | the other in your aliases. | |
1430 |
|
|
1434 | ||
1431 |
|
|
1435 | Aliases expand Python variables just like system calls using ! or !! | |
1432 |
|
|
1436 | do: all expressions prefixed with '$' get expanded. For details of | |
1433 | semantic rules, see PEP-215: http://www.python.org/peps/pep-0215.html. |
|
1437 | the semantic rules, see PEP-215: | |
1434 | This is the library used by IPython for variable expansion. If you want |
|
1438 | http://www.python.org/peps/pep-0215.html. This is the library used by | |
1435 | to access a true shell variable, an extra $ is necessary to prevent its |
|
1439 | IPython for variable expansion. If you want to access a true shell | |
1436 | expansion by IPython: |
|
1440 | variable, an extra $ is necessary to prevent its expansion by IPython: | |
1437 |
|
|
1441 | ||
1438 |
|
|
1442 | In [6]: alias show echo\ | |
1439 |
|
|
1443 | In [7]: PATH='A Python string'\ | |
1440 |
|
|
1444 | In [8]: show $PATH\ | |
1441 |
|
|
1445 | A Python string\ | |
1442 |
|
|
1446 | In [9]: show $$PATH\ | |
1443 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
|
1447 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... | |
1444 |
|
1448 | |||
1445 | You can use the alias facility to acess all of $PATH. See the %rehash |
|
1449 | You can use the alias facility to acess all of $PATH. See the %rehash | |
@@ -1448,8 +1452,9 b' customizations.' | |||||
1448 |
|
1452 | |||
1449 | If called with no parameters, %alias prints the current alias table. |
|
1453 | If called with no parameters, %alias prints the current alias table. | |
1450 |
|
1454 | |||
|
1455 | **%autocall**:: | |||
1451 |
|
1456 | |||
1452 |
|
|
1457 | Make functions callable without having to type parentheses. | |
1453 |
|
1458 | |||
1454 | Usage: |
|
1459 | Usage: | |
1455 |
|
1460 | |||
@@ -1466,27 +1471,34 b' customizations.' | |||||
1466 |
|
1471 | |||
1467 | In this mode, you get: |
|
1472 | In this mode, you get: | |
1468 |
|
1473 | |||
1469 | In [1]: callable Out[1]: <built-in function callable> |
|
1474 | In [1]: callable | |
|
1475 | Out[1]: <built-in function callable> | |||
1470 |
|
1476 | |||
1471 | In [2]: callable 'hello' ---> callable('hello') Out[2]: False |
|
1477 | In [2]: callable 'hello' | |
|
1478 | ------> callable('hello') | |||
|
1479 | Out[2]: False | |||
1472 |
|
1480 | |||
1473 | 2 -> Active always. Even if no arguments are present, the callable |
|
1481 | 2 -> Active always. Even if no arguments are present, the callable | |
1474 | object is called: |
|
1482 | object is called: | |
1475 |
|
1483 | |||
1476 | In [4]: callable ---> callable() |
|
1484 | In [4]: callable | |
|
1485 | ------> callable() | |||
1477 |
|
1486 | |||
1478 | Note that even with autocall off, you can still use '/' at the start of |
|
1487 | Note that even with autocall off, you can still use '/' at the start of | |
1479 |
|
|
1488 | a line to treat the first argument on the command line as a function | |
1480 |
|
|
1489 | and add parentheses to it: | |
1481 |
|
1490 | |||
1482 | In [8]: /str 43 ---> str(43) Out[8]: '43' |
|
1491 | In [8]: /str 43 | |
|
1492 | ------> str(43) | |||
|
1493 | Out[8]: '43' | |||
1483 |
|
1494 | |||
|
1495 | **%autoindent**:: | |||
1484 |
|
1496 | |||
1485 |
|
|
1497 | Toggle autoindent on/off (if available). | |
1486 |
|
1498 | |||
|
1499 | **%automagic**:: | |||
1487 |
|
1500 | |||
1488 |
|
|
1501 | Make magic functions callable without having to type the initial %. | |
1489 | initial %. |
|
|||
1490 |
|
1502 | |||
1491 | Without argumentsl toggles on/off (when off, you must call it as |
|
1503 | Without argumentsl toggles on/off (when off, you must call it as | |
1492 | %automagic, of course). With arguments it sets the value, and you can |
|
1504 | %automagic, of course). With arguments it sets the value, and you can | |
@@ -1496,22 +1508,23 b' customizations.' | |||||
1496 |
|
1508 | |||
1497 | - off,0,False: to deactivate. |
|
1509 | - off,0,False: to deactivate. | |
1498 |
|
1510 | |||
1499 |
|
|
1511 | Note that magic functions have lowest priority, so if there's a | |
1500 |
|
|
1512 | variable whose name collides with that of a magic fn, automagic won't | |
1501 |
|
|
1513 | work for that function (you get the variable instead). However, if you | |
1502 |
|
|
1514 | delete the variable (del var), the previously shadowed magic function | |
1503 |
|
|
1515 | becomes visible to automagic again. | |
1504 |
|
1516 | |||
|
1517 | **%bg**:: | |||
1505 |
|
1518 | |||
1506 |
|
|
1519 | Run a job in the background, in a separate thread. | |
1507 |
|
1520 | |||
1508 | For example, |
|
1521 | For example, | |
1509 |
|
1522 | |||
1510 | %bg myfunc(x,y,z=1) |
|
1523 | %bg myfunc(x,y,z=1) | |
1511 |
|
1524 | |||
1512 | will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the |
|
1525 | will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the | |
1513 |
|
|
1526 | execution starts, a message will be printed indicating the job | |
1514 |
|
|
1527 | number. If your job number is 5, you can use | |
1515 |
|
1528 | |||
1516 | myvar = jobs.result(5) or myvar = jobs[5].result |
|
1529 | myvar = jobs.result(5) or myvar = jobs[5].result | |
1517 |
|
1530 | |||
@@ -1519,14 +1532,14 b' customizations.' | |||||
1519 |
|
1532 | |||
1520 | IPython has a job manager, accessible via the 'jobs' object. You can |
|
1533 | IPython has a job manager, accessible via the 'jobs' object. You can | |
1521 | type jobs? to get more information about it, and use jobs.<TAB> to see |
|
1534 | type jobs? to get more information about it, and use jobs.<TAB> to see | |
1522 |
|
|
1535 | its attributes. All attributes not starting with an underscore are | |
1523 |
|
|
1536 | meant for public use. | |
1524 |
|
1537 | |||
1525 | In particular, look at the jobs.new() method, which is used to create |
|
1538 | In particular, look at the jobs.new() method, which is used to create | |
1526 |
|
|
1539 | new jobs. This magic %bg function is just a convenience wrapper | |
1527 |
|
|
1540 | around jobs.new(), for expression-based jobs. If you want to create a | |
1528 |
|
|
1541 | new job with an explicit function object and arguments, you must call | |
1529 | directly. |
|
1542 | jobs.new() directly. | |
1530 |
|
1543 | |||
1531 | The jobs.new docstring also describes in detail several important |
|
1544 | The jobs.new docstring also describes in detail several important | |
1532 | caveats associated with a thread-based model for background job |
|
1545 | caveats associated with a thread-based model for background job | |
@@ -1535,35 +1548,40 b' customizations.' | |||||
1535 | You can check the status of all jobs with jobs.status(). |
|
1548 | You can check the status of all jobs with jobs.status(). | |
1536 |
|
1549 | |||
1537 | The jobs variable is set by IPython into the Python builtin namespace. |
|
1550 | The jobs variable is set by IPython into the Python builtin namespace. | |
1538 |
|
|
1551 | If you ever declare a variable named 'jobs', you will shadow this | |
1539 |
|
|
1552 | name. You can either delete your global jobs variable to regain | |
1540 |
|
|
1553 | access to the job manager, or make a new name and assign it manually | |
1541 |
|
|
1554 | to the manager (stored in IPython's namespace). For example, to | |
1542 | to the Jobs name, use: |
|
1555 | assign the job manager to the Jobs name, use: | |
1543 |
|
1556 | |||
1544 | Jobs = __builtins__.jobs |
|
1557 | Jobs = __builtins__.jobs | |
1545 |
|
1558 | |||
|
1559 | **%bookmark**:: | |||
1546 |
|
1560 | |||
1547 |
|
|
1561 | Manage IPython's bookmark system. | |
1548 |
|
1562 | |||
1549 |
|
|
1563 | %bookmark <name> - set bookmark to current dir | |
1550 | set bookmark to <dir> %bookmark -l - list all bookmarks %bookmark -d |
|
1564 | %bookmark <name> <dir> - set bookmark to <dir> | |
1551 | <name> - remove bookmark %bookmark -r - remove all bookmarks |
|
1565 | %bookmark -l - list all bookmarks | |
|
1566 | %bookmark -d <name> - remove bookmark | |||
|
1567 | %bookmark -r - remove all bookmarks | |||
1552 |
|
1568 | |||
1553 |
|
|
1569 | You can later on access a bookmarked folder with: | |
1554 | simply '%cd <name>' if there is no directory called <name> AND there is |
|
1570 | %cd -b <name> | |
1555 | such a bookmark defined. |
|
1571 | or simply '%cd <name>' if there is no directory called <name> AND | |
|
1572 | there is such a bookmark defined. | |||
1556 |
|
1573 | |||
1557 |
|
|
1574 | Your bookmarks persist through IPython sessions, but they are | |
1558 |
|
|
1575 | associated with each profile. | |
1559 |
|
1576 | |||
|
1577 | **%cd**:: | |||
1560 |
|
1578 | |||
1561 |
|
|
1579 | Change the current working directory. | |
1562 |
|
1580 | |||
1563 |
|
|
1581 | This command automatically maintains an internal list of directories | |
1564 |
|
|
1582 | you visit during your IPython session, in the variable _dh. The | |
1565 |
|
|
1583 | command %dhist shows this history nicely formatted. You can also | |
1566 |
|
|
1584 | do 'cd -<tab>' to see directory history conveniently. | |
1567 |
|
1585 | |||
1568 | Usage: |
|
1586 | Usage: | |
1569 |
|
1587 | |||
@@ -1573,10 +1591,10 b' customizations.' | |||||
1573 |
|
1591 | |||
1574 | cd -<n>: changes to the n-th directory in the directory history. |
|
1592 | cd -<n>: changes to the n-th directory in the directory history. | |
1575 |
|
1593 | |||
1576 |
|
|
1594 | cd -b <bookmark_name>: jump to a bookmark set by %bookmark | |
1577 | <bookmark_name> is enough if there is no directory <bookmark_name>, but |
|
1595 | (note: cd <bookmark_name> is enough if there is no | |
1578 | a bookmark with the name exists.) 'cd -b <tab>' allows you to |
|
1596 | directory <bookmark_name>, but a bookmark with the name exists.) | |
1579 | tab-complete bookmark names. |
|
1597 | 'cd -b <tab>' allows you to tab-complete bookmark names. | |
1580 |
|
1598 | |||
1581 | Options: |
|
1599 | Options: | |
1582 |
|
1600 | |||
@@ -1587,30 +1605,41 b' customizations.' | |||||
1587 | Note that !cd doesn't work for this purpose because the shell where |
|
1605 | Note that !cd doesn't work for this purpose because the shell where | |
1588 | !command runs is immediately discarded after executing 'command'. |
|
1606 | !command runs is immediately discarded after executing 'command'. | |
1589 |
|
1607 | |||
|
1608 | **%clear**:: | |||
|
1609 | ||||
|
1610 | Clear various data (e.g. stored history data) | |||
1590 |
|
1611 | |||
1591 | %color_info: Toggle color_info. |
|
1612 | %clear out - clear output history | |
|
1613 | %clear in - clear input history | |||
|
1614 | %clear shadow_compress - Compresses shadow history (to speed up ipython) | |||
|
1615 | %clear shadow_nuke - permanently erase all entries in shadow history | |||
|
1616 | %clear dhist - clear dir history | |||
1592 |
|
1617 | |||
1593 | The color_info configuration parameter controls whether colors are used |
|
1618 | **%color_info**:: | |
1594 | for displaying object details (by things like %psource, %pfile or the |
|
|||
1595 | '?' system). This function toggles this value with each call. |
|
|||
1596 |
|
1619 | |||
1597 | Note that unless you have a fairly recent pager (less works better than |
|
1620 | Toggle color_info. | |
1598 | more) in your system, using colored object information displays will not |
|
|||
1599 | work properly. Test it and see. |
|
|||
1600 |
|
1621 | |||
|
1622 | The color_info configuration parameter controls whether colors are | |||
|
1623 | used for displaying object details (by things like %psource, %pfile or | |||
|
1624 | the '?' system). This function toggles this value with each call. | |||
1601 |
|
1625 | |||
1602 | %colors: Switch color scheme for prompts, info system and exception |
|
1626 | Note that unless you have a fairly recent pager (less works better | |
1603 | handlers. |
|
1627 | than more) in your system, using colored object information displays | |
|
1628 | will not work properly. Test it and see. | |||
|
1629 | ||||
|
1630 | **%colors**:: | |||
|
1631 | ||||
|
1632 | Switch color scheme for prompts, info system and exception handlers. | |||
1604 |
|
1633 | |||
1605 | Currently implemented schemes: NoColor, Linux, LightBG. |
|
1634 | Currently implemented schemes: NoColor, Linux, LightBG. | |
1606 |
|
1635 | |||
1607 | Color scheme names are not case-sensitive. |
|
1636 | Color scheme names are not case-sensitive. | |
1608 |
|
1637 | |||
|
1638 | **%cpaste**:: | |||
1609 |
|
1639 | |||
1610 |
|
|
1640 | Allows you to paste & execute a pre-formatted code block from clipboard | |
1611 | clipboard |
|
|||
1612 |
|
1641 | |||
1613 |
|
|
1642 | You must terminate the block with '--' (two minus-signs) alone on the | |
1614 | line. You can also provide your own sentinel with '%paste -s %%' ('%%' |
|
1643 | line. You can also provide your own sentinel with '%paste -s %%' ('%%' | |
1615 | is the new sentinel for this operation) |
|
1644 | is the new sentinel for this operation) | |
1616 |
|
1645 | |||
@@ -1625,13 +1654,14 b' customizations.' | |||||
1625 | dedenting or executing it. |
|
1654 | dedenting or executing it. | |
1626 |
|
1655 | |||
1627 | Do not be alarmed by garbled output on Windows (it's a readline bug). |
|
1656 | Do not be alarmed by garbled output on Windows (it's a readline bug). | |
1628 |
|
|
1657 | Just press enter and type -- (and press enter again) and the block | |
1629 |
|
|
1658 | will be what was just pasted. | |
1630 |
|
1659 | |||
1631 | IPython statements (magics, shell escapes) are not supported (yet). |
|
1660 | IPython statements (magics, shell escapes) are not supported (yet). | |
1632 |
|
1661 | |||
|
1662 | **%debug**:: | |||
1633 |
|
1663 | |||
1634 |
|
|
1664 | Activate the interactive debugger in post-mortem mode. | |
1635 |
|
1665 | |||
1636 | If an exception has just occurred, this lets you inspect its stack |
|
1666 | If an exception has just occurred, this lets you inspect its stack | |
1637 | frames interactively. Note that this will always work only on the last |
|
1667 | frames interactively. Note that this will always work only on the last | |
@@ -1639,57 +1669,63 b' customizations.' | |||||
1639 | exception that you wish to inspect has fired, because if another one |
|
1669 | exception that you wish to inspect has fired, because if another one | |
1640 | occurs, it clobbers the previous one. |
|
1670 | occurs, it clobbers the previous one. | |
1641 |
|
1671 | |||
1642 |
|
|
1672 | If you want IPython to automatically do this on every exception, see | |
1643 |
|
|
1673 | the %pdb magic for more details. | |
1644 |
|
1674 | |||
|
1675 | **%dhist**:: | |||
1645 |
|
1676 | |||
1646 |
|
|
1677 | Print your history of visited directories. | |
1647 |
|
1678 | |||
1648 |
|
|
1679 | %dhist -> print full history\ | |
1649 |
|
|
1680 | %dhist n -> print last n entries only\ | |
1650 |
|
|
1681 | %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\ | |
1651 |
|
1682 | |||
1652 |
|
|
1683 | This history is automatically maintained by the %cd command, and | |
1653 |
|
|
1684 | always available as the global list variable _dh. You can use %cd -<n> | |
1654 |
|
|
1685 | to go to directory number <n>. | |
1655 |
|
1686 | |||
1656 |
|
|
1687 | Note that most of time, you should view directory history by entering | |
1657 | -<TAB>. |
|
1688 | cd -<TAB>. | |
1658 |
|
1689 | |||
|
1690 | **%dirs**:: | |||
1659 |
|
1691 | |||
1660 |
|
|
1692 | Return the current directory stack. | |
1661 |
|
1693 | |||
|
1694 | **%doctest_mode**:: | |||
1662 |
|
1695 | |||
1663 |
|
|
1696 | Toggle doctest mode on and off. | |
1664 |
|
1697 | |||
1665 | This mode allows you to toggle the prompt behavior between normal |
|
1698 | This mode allows you to toggle the prompt behavior between normal | |
1666 | IPython prompts and ones that are as similar to the default IPython |
|
1699 | IPython prompts and ones that are as similar to the default IPython | |
1667 | interpreter as possible. |
|
1700 | interpreter as possible. | |
1668 |
|
1701 | |||
1669 |
|
|
1702 | It also supports the pasting of code snippets that have leading '>>>' | |
1670 |
|
|
1703 | and '...' prompts in them. This means that you can paste doctests from | |
1671 |
|
|
1704 | files or docstrings (even if they have leading whitespace), and the | |
1672 |
|
|
1705 | code will execute correctly. You can then use '%history -tn' to see | |
1673 |
|
|
1706 | the translated history without line numbers; this will give you the | |
1674 |
|
|
1707 | input after removal of all the leading prompts and whitespace, which | |
1675 | an editor. |
|
1708 | can be pasted back into an editor. | |
1676 |
|
1709 | |||
1677 | With these features, you can switch into this mode easily whenever you |
|
1710 | With these features, you can switch into this mode easily whenever you | |
1678 |
|
|
1711 | need to do testing and changes to doctests, without having to leave | |
1679 |
|
|
1712 | your existing IPython session. | |
1680 |
|
1713 | |||
|
1714 | **%ed**:: | |||
1681 |
|
1715 | |||
1682 |
|
|
1716 | Alias to %edit. | |
1683 |
|
1717 | |||
|
1718 | **%edit**:: | |||
1684 |
|
1719 | |||
1685 |
|
|
1720 | Bring up an editor and execute the resulting code. | |
1686 |
|
1721 | |||
1687 | Usage: %edit [options] [args] |
|
1722 | Usage: | |
|
1723 | %edit [options] [args] | |||
1688 |
|
1724 | |||
1689 | %edit runs IPython's editor hook. The default version of this hook is |
|
1725 | %edit runs IPython's editor hook. The default version of this hook is | |
1690 | set to call the __IPYTHON__.rc.editor command. This is read from your |
|
1726 | set to call the __IPYTHON__.rc.editor command. This is read from your | |
1691 |
|
|
1727 | environment variable $EDITOR. If this isn't found, it will default to | |
1692 |
|
|
1728 | vi under Linux/Unix and to notepad under Windows. See the end of this | |
1693 | docstring for how to change the editor hook. |
|
1729 | docstring for how to change the editor hook. | |
1694 |
|
1730 | |||
1695 | You can also set the value of this editor via the command line option |
|
1731 | You can also set the value of this editor via the command line option | |
@@ -1701,251 +1737,309 b' customizations.' | |||||
1701 | your IPython session. |
|
1737 | your IPython session. | |
1702 |
|
1738 | |||
1703 | If called without arguments, %edit opens up an empty editor with a |
|
1739 | If called without arguments, %edit opens up an empty editor with a | |
1704 |
|
|
1740 | temporary file and will execute the contents of this file when you | |
1705 |
|
|
1741 | close it (don't forget to save it!). | |
|
1742 | ||||
1706 |
|
1743 | |||
1707 | Options: |
|
1744 | Options: | |
1708 |
|
1745 | |||
1709 |
|
|
1746 | -n <number>: open the editor at a specified line number. By default, | |
1710 |
|
|
1747 | the IPython editor hook uses the unix syntax 'editor +N filename', but | |
1711 |
|
|
1748 | you can configure this by providing your own modified hook if your | |
1712 |
|
|
1749 | favorite editor supports line-number specifications with a different | |
|
1750 | syntax. | |||
1713 |
|
1751 | |||
1714 |
|
|
1752 | -p: this will call the editor with the same data as the previous time | |
1715 |
|
|
1753 | it was used, regardless of how long ago (in your current session) it | |
|
1754 | was. | |||
1716 |
|
1755 | |||
1717 | -r: use 'raw' input. This option only applies to input taken from the |
|
1756 | -r: use 'raw' input. This option only applies to input taken from the | |
1718 | user's history. By default, the 'processed' history is used, so that |
|
1757 | user's history. By default, the 'processed' history is used, so that | |
1719 |
|
|
1758 | magics are loaded in their transformed version to valid Python. If | |
1720 |
|
|
1759 | this option is given, the raw input as typed as the command line is | |
1721 |
|
|
1760 | used instead. When you exit the editor, it will be executed by | |
1722 | processor. |
|
1761 | IPython's own processor. | |
|
1762 | ||||
|
1763 | -x: do not execute the edited code immediately upon exit. This is | |||
|
1764 | mainly useful if you are editing programs which need to be called with | |||
|
1765 | command line arguments, which you can then do using %run. | |||
1723 |
|
1766 | |||
1724 | -x: do not execute the edited code immediately upon exit. This is mainly |
|
|||
1725 | useful if you are editing programs which need to be called with command |
|
|||
1726 | line arguments, which you can then do using %run. |
|
|||
1727 |
|
1767 | |||
1728 | Arguments: |
|
1768 | Arguments: | |
1729 |
|
1769 | |||
1730 | If arguments are given, the following possibilites exist: |
|
1770 | If arguments are given, the following possibilites exist: | |
1731 |
|
1771 | |||
1732 |
|
|
1772 | - The arguments are numbers or pairs of colon-separated numbers (like | |
1733 |
|
|
1773 | 1 4:8 9). These are interpreted as lines of previous input to be | |
1734 |
|
|
1774 | loaded into the editor. The syntax is the same of the %macro command. | |
1735 |
|
1775 | |||
1736 | - If the argument doesn't start with a number, it is evaluated as a |
|
1776 | - If the argument doesn't start with a number, it is evaluated as a | |
1737 |
|
|
1777 | variable and its contents loaded into the editor. You can thus edit | |
1738 |
|
|
1778 | any string which contains python code (including the result of | |
|
1779 | previous edits). | |||
1739 |
|
1780 | |||
1740 | - If the argument is the name of an object (other than a string), |
|
1781 | - If the argument is the name of an object (other than a string), | |
1741 | IPython will try to locate the file where it was defined and open the |
|
1782 | IPython will try to locate the file where it was defined and open the | |
1742 |
|
|
1783 | editor at the point where it is defined. You can use `%edit function` | |
1743 |
|
|
1784 | to load an editor exactly at the point where 'function' is defined, | |
1744 |
|
|
1785 | edit it and have the file be executed automatically. | |
1745 |
|
1786 | |||
1746 | If the object is a macro (see %macro for details), this opens up your |
|
1787 | If the object is a macro (see %macro for details), this opens up your | |
1747 |
|
|
1788 | specified editor with a temporary file containing the macro's data. | |
1748 |
|
|
1789 | Upon exit, the macro is reloaded with the contents of the file. | |
1749 |
|
1790 | |||
1750 | Note: opening at an exact line is only supported under Unix, and some |
|
1791 | Note: opening at an exact line is only supported under Unix, and some | |
1751 | editors (like kedit and gedit up to Gnome 2.8) do not understand the |
|
1792 | editors (like kedit and gedit up to Gnome 2.8) do not understand the | |
1752 | '+NUMBER' parameter necessary for this feature. Good editors like |
|
1793 | '+NUMBER' parameter necessary for this feature. Good editors like | |
1753 | (X)Emacs, vi, jed, pico and joe all do. |
|
1794 | (X)Emacs, vi, jed, pico and joe all do. | |
1754 |
|
1795 | |||
1755 |
|
|
1796 | - If the argument is not found as a variable, IPython will look for a | |
1756 | file with that name (adding .py if necessary) and load it into the |
|
1797 | file with that name (adding .py if necessary) and load it into the | |
1757 | editor. It will execute its contents with execfile() when you exit, |
|
1798 | editor. It will execute its contents with execfile() when you exit, | |
1758 | loading any code in the file into your interactive namespace. |
|
1799 | loading any code in the file into your interactive namespace. | |
1759 |
|
1800 | |||
1760 | After executing your code, %edit will return as output the code you |
|
1801 | After executing your code, %edit will return as output the code you | |
1761 |
|
|
1802 | typed in the editor (except when it was an existing file). This way | |
1762 |
|
|
1803 | you can reload the code in further invocations of %edit as a variable, | |
1763 |
|
|
1804 | via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of | |
1764 | output. |
|
1805 | the output. | |
1765 |
|
1806 | |||
1766 | Note that %edit is also available through the alias %ed. |
|
1807 | Note that %edit is also available through the alias %ed. | |
1767 |
|
1808 | |||
1768 | This is an example of creating a simple function inside the editor and |
|
1809 | This is an example of creating a simple function inside the editor and | |
1769 |
|
|
1810 | then modifying it. First, start up the editor: | |
1770 |
|
1811 | |||
1771 |
|
|
1812 | In [1]: ed\ | |
1772 |
|
|
1813 | Editing... done. Executing edited code...\ | |
1773 | Out[1]: 'def foo():\n print "foo() was defined in an editing session"\n' |
|
1814 | Out[1]: 'def foo():\n print "foo() was defined in an editing session"\n' | |
1774 |
|
1815 | |||
1775 | We can then call the function foo(): |
|
1816 | We can then call the function foo(): | |
1776 |
|
1817 | |||
1777 |
|
|
1818 | In [2]: foo()\ | |
1778 | foo() was defined in an editing session |
|
1819 | foo() was defined in an editing session | |
1779 |
|
1820 | |||
1780 | Now we edit foo. IPython automatically loads the editor with the |
|
1821 | Now we edit foo. IPython automatically loads the editor with the | |
1781 | (temporary) file where foo() was previously defined: |
|
1822 | (temporary) file where foo() was previously defined: | |
1782 |
|
1823 | |||
1783 |
|
|
1824 | In [3]: ed foo\ | |
1784 | Editing... done. Executing edited code... |
|
1825 | Editing... done. Executing edited code... | |
1785 |
|
1826 | |||
1786 | And if we call foo() again we get the modified version: |
|
1827 | And if we call foo() again we get the modified version: | |
1787 |
|
1828 | |||
1788 |
|
|
1829 | In [4]: foo()\ | |
1789 | foo() has now been changed! |
|
1830 | foo() has now been changed! | |
1790 |
|
1831 | |||
1791 |
|
|
1832 | Here is an example of how to edit a code snippet successive | |
1792 |
|
|
1833 | times. First we call the editor: | |
1793 |
|
1834 | |||
1794 |
|
|
1835 | In [8]: ed\ | |
1795 |
|
|
1836 | Editing... done. Executing edited code...\ | |
1796 |
|
|
1837 | hello\ | |
1797 | Out[8]: "print 'hello'\n" |
|
1838 | Out[8]: "print 'hello'\n" | |
1798 |
|
1839 | |||
1799 | Now we call it again with the previous output (stored in _): |
|
1840 | Now we call it again with the previous output (stored in _): | |
1800 |
|
1841 | |||
1801 |
|
|
1842 | In [9]: ed _\ | |
1802 |
|
|
1843 | Editing... done. Executing edited code...\ | |
1803 |
|
|
1844 | hello world\ | |
1804 | Out[9]: "print 'hello world'\n" |
|
1845 | Out[9]: "print 'hello world'\n" | |
1805 |
|
1846 | |||
1806 | Now we call it with the output #8 (stored in _8, also as Out[8]): |
|
1847 | Now we call it with the output #8 (stored in _8, also as Out[8]): | |
1807 |
|
1848 | |||
1808 |
|
|
1849 | In [10]: ed _8\ | |
1809 |
|
|
1850 | Editing... done. Executing edited code...\ | |
1810 |
|
|
1851 | hello again\ | |
1811 | Out[10]: "print 'hello again'\n" |
|
1852 | Out[10]: "print 'hello again'\n" | |
1812 |
|
1853 | |||
|
1854 | ||||
1813 | Changing the default editor hook: |
|
1855 | Changing the default editor hook: | |
1814 |
|
1856 | |||
1815 | If you wish to write your own editor hook, you can put it in a |
|
1857 | If you wish to write your own editor hook, you can put it in a | |
1816 |
|
|
1858 | configuration file which you load at startup time. The default hook | |
1817 |
|
|
1859 | is defined in the IPython.hooks module, and you can use that as a | |
1818 |
|
|
1860 | starting example for further modifications. That file also has | |
1819 |
|
|
1861 | general instructions on how to set a new hook for use once you've | |
|
1862 | defined it. | |||
1820 |
|
1863 | |||
|
1864 | **%env**:: | |||
1821 |
|
1865 | |||
1822 |
|
|
1866 | List environment variables. | |
1823 |
|
1867 | |||
|
1868 | **%exit**:: | |||
1824 |
|
1869 | |||
1825 |
|
|
1870 | Exit IPython, confirming if configured to do so. | |
1826 |
|
1871 | |||
1827 | You can configure whether IPython asks for confirmation upon exit by |
|
1872 | You can configure whether IPython asks for confirmation upon exit by | |
1828 | setting the confirm_exit flag in the ipythonrc file. |
|
1873 | setting the confirm_exit flag in the ipythonrc file. | |
1829 |
|
1874 | |||
|
1875 | **%hist**:: | |||
|
1876 | ||||
|
1877 | Alternate name for %history. | |||
|
1878 | ||||
|
1879 | **%history**:: | |||
|
1880 | ||||
|
1881 | Print input history (_i<n> variables), with most recent last. | |||
|
1882 | ||||
|
1883 | %history -> print at most 40 inputs (some may be multi-line)\ | |||
|
1884 | %history n -> print at most n inputs\ | |||
|
1885 | %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\ | |||
1830 |
|
1886 | |||
1831 | %logoff: Temporarily stop logging. |
|
1887 | Each input's number <n> is shown, and is accessible as the | |
|
1888 | automatically generated variable _i<n>. Multi-line statements are | |||
|
1889 | printed starting at a new line for easy copy/paste. | |||
|
1890 | ||||
|
1891 | ||||
|
1892 | Options: | |||
|
1893 | ||||
|
1894 | -n: do NOT print line numbers. This is useful if you want to get a | |||
|
1895 | printout of many lines which can be directly pasted into a text | |||
|
1896 | editor. | |||
|
1897 | ||||
|
1898 | This feature is only available if numbered prompts are in use. | |||
|
1899 | ||||
|
1900 | -t: (default) print the 'translated' history, as IPython understands it. | |||
|
1901 | IPython filters your input and converts it all into valid Python source | |||
|
1902 | before executing it (things like magics or aliases are turned into | |||
|
1903 | function calls, for example). With this option, you'll see the native | |||
|
1904 | history instead of the user-entered version: '%cd /' will be seen as | |||
|
1905 | '_ip.magic("%cd /")' instead of '%cd /'. | |||
|
1906 | ||||
|
1907 | -r: print the 'raw' history, i.e. the actual commands you typed. | |||
|
1908 | ||||
|
1909 | -g: treat the arg as a pattern to grep for in (full) history. | |||
|
1910 | This includes the "shadow history" (almost all commands ever written). | |||
|
1911 | Use '%hist -g' to show full shadow history (may be very long). | |||
|
1912 | In shadow history, every index nuwber starts with 0. | |||
|
1913 | ||||
|
1914 | -f FILENAME: instead of printing the output to the screen, redirect it to | |||
|
1915 | the given file. The file is always overwritten, though IPython asks for | |||
|
1916 | confirmation first if it already exists. | |||
|
1917 | ||||
|
1918 | **%logoff**:: | |||
|
1919 | ||||
|
1920 | Temporarily stop logging. | |||
1832 |
|
1921 | |||
1833 | You must have previously started logging. |
|
1922 | You must have previously started logging. | |
1834 |
|
1923 | |||
|
1924 | **%logon**:: | |||
1835 |
|
1925 | |||
1836 |
|
|
1926 | Restart logging. | |
1837 |
|
1927 | |||
1838 |
|
|
1928 | This function is for restarting logging which you've temporarily | |
1839 |
|
|
1929 | stopped with %logoff. For starting logging for the first time, you | |
1840 |
|
|
1930 | must use the %logstart function, which allows you to specify an | |
|
1931 | optional log filename. | |||
1841 |
|
1932 | |||
|
1933 | **%logstart**:: | |||
1842 |
|
1934 | |||
1843 |
|
|
1935 | Start logging anywhere in a session. | |
1844 |
|
1936 | |||
1845 | %logstart [-o|-r|-t] [log_name [log_mode]] |
|
1937 | %logstart [-o|-r|-t] [log_name [log_mode]] | |
1846 |
|
1938 | |||
1847 |
|
|
1939 | If no name is given, it defaults to a file named 'ipython_log.py' in your | |
1848 |
|
|
1940 | current directory, in 'rotate' mode (see below). | |
1849 |
|
1941 | |||
1850 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your |
|
1942 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your | |
1851 | history up to that point and then continues logging. |
|
1943 | history up to that point and then continues logging. | |
1852 |
|
1944 | |||
1853 |
|
|
1945 | %logstart takes a second optional parameter: logging mode. This can be one | |
1854 |
|
|
1946 | of (note that the modes are given unquoted):\ | |
1855 |
|
|
1947 | append: well, that says it.\ | |
1856 |
|
|
1948 | backup: rename (if exists) to name~ and start name.\ | |
1857 |
|
|
1949 | global: single logfile in your home dir, appended to.\ | |
1858 |
|
|
1950 | over : overwrite existing log.\ | |
1859 |
|
|
1951 | rotate: create rotating logs name.1~, name.2~, etc. | |
1860 |
|
1952 | |||
1861 | Options: |
|
1953 | Options: | |
1862 |
|
1954 | |||
1863 |
|
|
1955 | -o: log also IPython's output. In this mode, all commands which | |
1864 |
|
|
1956 | generate an Out[NN] prompt are recorded to the logfile, right after | |
1865 |
|
|
1957 | their corresponding input line. The output lines are always | |
1866 |
|
|
1958 | prepended with a '#[Out]# ' marker, so that the log remains valid | |
|
1959 | Python code. | |||
1867 |
|
1960 | |||
1868 |
|
|
1961 | Since this marker is always the same, filtering only the output from | |
1869 |
|
|
1962 | a log is very easy, using for example a simple awk call: | |
1870 |
|
1963 | |||
1871 | awk -F'# |
|
1964 | awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py | |
1872 |
|
||||
1873 | \begin{displaymath}Out\end{displaymath} |
|
|||
1874 |
|
||||
1875 | # ' 'if($2) print $2' ipython_log.py |
|
|||
1876 |
|
1965 | |||
1877 | -r: log 'raw' input. Normally, IPython's logs contain the processed |
|
1966 | -r: log 'raw' input. Normally, IPython's logs contain the processed | |
1878 |
|
|
1967 | input, so that user lines are logged in their final form, converted | |
1879 |
|
|
1968 | into valid Python. For example, %Exit is logged as | |
1880 | -r flag is given, all input is logged exactly as typed, with no |
|
1969 | '_ip.magic("Exit"). If the -r flag is given, all input is logged | |
1881 | transformations applied. |
|
1970 | exactly as typed, with no transformations applied. | |
1882 |
|
1971 | |||
1883 | -t: put timestamps before each input line logged (these are put in |
|
1972 | -t: put timestamps before each input line logged (these are put in | |
1884 | comments). |
|
1973 | comments). | |
1885 |
|
1974 | |||
|
1975 | **%logstate**:: | |||
1886 |
|
1976 | |||
1887 |
|
|
1977 | Print the status of the logging system. | |
1888 |
|
1978 | |||
|
1979 | **%logstop**:: | |||
1889 |
|
1980 | |||
1890 |
|
|
1981 | Fully stop logging and close log file. | |
1891 |
|
1982 | |||
1892 | In order to start logging again, a new %logstart call needs to be made, |
|
1983 | In order to start logging again, a new %logstart call needs to be made, | |
1893 | possibly (though not necessarily) with a new filename, mode and other |
|
1984 | possibly (though not necessarily) with a new filename, mode and other | |
1894 | options. |
|
1985 | options. | |
1895 |
|
1986 | |||
|
1987 | **%lsmagic**:: | |||
1896 |
|
1988 | |||
1897 |
|
|
1989 | List currently available magic functions. | |
1898 |
|
1990 | |||
|
1991 | **%macro**:: | |||
1899 |
|
1992 | |||
1900 |
|
|
1993 | Define a set of input lines as a macro for future re-execution. | |
1901 |
|
1994 | |||
1902 | Usage: |
|
1995 | Usage:\ | |
1903 | %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ... |
|
1996 | %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ... | |
1904 |
|
1997 | |||
1905 | Options: |
|
1998 | Options: | |
1906 |
|
1999 | |||
1907 |
|
|
2000 | -r: use 'raw' input. By default, the 'processed' history is used, | |
1908 |
|
|
2001 | so that magics are loaded in their transformed version to valid | |
1909 |
|
|
2002 | Python. If this option is given, the raw input as typed as the | |
1910 | instead. |
|
2003 | command line is used instead. | |
1911 |
|
2004 | |||
1912 |
|
|
2005 | This will define a global variable called `name` which is a string | |
1913 |
|
|
2006 | made of joining the slices and lines you specify (n1,n2,... numbers | |
1914 |
|
|
2007 | above) from your input history into a single string. This variable | |
1915 |
|
|
2008 | acts like an automatic function which re-executes those lines as if | |
1916 |
|
|
2009 | you had typed them. You just type 'name' at the prompt and the code | |
|
2010 | executes. | |||
1917 |
|
2011 | |||
1918 | The notation for indicating number ranges is: n1-n2 means 'use line |
|
2012 | The notation for indicating number ranges is: n1-n2 means 'use line | |
1919 |
|
|
2013 | numbers n1,...n2' (the endpoint is included). That is, '5-7' means | |
1920 |
|
|
2014 | using the lines numbered 5,6 and 7. | |
1921 |
|
2015 | |||
1922 | Note: as a 'hidden' feature, you can also use traditional python slice |
|
2016 | Note: as a 'hidden' feature, you can also use traditional python slice | |
1923 | notation, where N:M means numbers N through M-1. |
|
2017 | notation, where N:M means numbers N through M-1. | |
1924 |
|
2018 | |||
1925 | For example, if your history contains (%hist prints it): |
|
2019 | For example, if your history contains (%hist prints it): | |
1926 |
|
2020 | |||
1927 | 44: x=1 |
|
2021 | 44: x=1\ | |
1928 | 45: y=3 |
|
2022 | 45: y=3\ | |
1929 |
|
|
2023 | 46: z=x+y\ | |
1930 |
|
|
2024 | 47: print x\ | |
1931 | 48: a=5 |
|
2025 | 48: a=5\ | |
1932 |
|
|
2026 | 49: print 'x',x,'y',y\ | |
1933 |
|
2027 | |||
1934 | you can create a macro with lines 44 through 47 (included) and line 49 |
|
2028 | you can create a macro with lines 44 through 47 (included) and line 49 | |
1935 | called my_macro with: |
|
2029 | called my_macro with: | |
1936 |
|
2030 | |||
1937 | In [51]: %macro my_macro 44-47 49 |
|
2031 | In [51]: %macro my_macro 44-47 49 | |
1938 |
|
2032 | |||
1939 |
|
|
2033 | Now, typing `my_macro` (without quotes) will re-execute all this code | |
1940 |
|
|
2034 | in one pass. | |
1941 |
|
2035 | |||
1942 | You don't need to give the line-numbers in order, and any given line |
|
2036 | You don't need to give the line-numbers in order, and any given line | |
1943 |
|
|
2037 | number can appear multiple times. You can assemble macros with any | |
1944 |
|
|
2038 | lines from your input history in any order. | |
1945 |
|
2039 | |||
1946 |
|
|
2040 | The macro is a simple object which holds its value in an attribute, | |
1947 |
|
|
2041 | but IPython's display system checks for macros and executes them as | |
1948 |
|
|
2042 | code instead of printing them when you type their name. | |
1949 |
|
2043 | |||
1950 | You can view a macro's contents by explicitly printing it with: |
|
2044 | You can view a macro's contents by explicitly printing it with: | |
1951 |
|
2045 | |||
@@ -1957,11 +2051,45 b' customizations.' | |||||
1957 |
|
2051 | |||
1958 | In [60]: exec In[44:48]+In[49] |
|
2052 | In [60]: exec In[44:48]+In[49] | |
1959 |
|
2053 | |||
1960 |
|
2054 | **%magic**:: | ||
1961 | %magic: Print information about the magic function system. |
|
2055 | ||
1962 |
|
2056 | Print information about the magic function system. | ||
1963 |
|
|
2057 | ||
1964 | %page: Pretty print the object and display it through a pager. |
|
2058 | **%mglob**:: | |
|
2059 | ||||
|
2060 | This program allows specifying filenames with "mglob" mechanism. | |||
|
2061 | Supported syntax in globs (wilcard matching patterns):: | |||
|
2062 | ||||
|
2063 | *.cpp ?ellowo* | |||
|
2064 | - obvious. Differs from normal glob in that dirs are not included. | |||
|
2065 | Unix users might want to write this as: "*.cpp" "?ellowo*" | |||
|
2066 | rec:/usr/share=*.txt,*.doc | |||
|
2067 | - get all *.txt and *.doc under /usr/share, | |||
|
2068 | recursively | |||
|
2069 | rec:/usr/share | |||
|
2070 | - All files under /usr/share, recursively | |||
|
2071 | rec:*.py | |||
|
2072 | - All .py files under current working dir, recursively | |||
|
2073 | foo | |||
|
2074 | - File or dir foo | |||
|
2075 | !*.bak readme* | |||
|
2076 | - readme*, exclude files ending with .bak | |||
|
2077 | !.svn/ !.hg/ !*_Data/ rec:. | |||
|
2078 | - Skip .svn, .hg, foo_Data dirs (and their subdirs) in recurse. | |||
|
2079 | Trailing / is the key, \ does not work! | |||
|
2080 | dir:foo | |||
|
2081 | - the directory foo if it exists (not files in foo) | |||
|
2082 | dir:* | |||
|
2083 | - all directories in current folder | |||
|
2084 | foo.py bar.* !h* rec:*.py | |||
|
2085 | - Obvious. !h* exclusion only applies for rec:*.py. | |||
|
2086 | foo.py is *not* included twice. | |||
|
2087 | @filelist.txt | |||
|
2088 | - All files listed in 'filelist.txt' file, on separate lines. | |||
|
2089 | ||||
|
2090 | **%page**:: | |||
|
2091 | ||||
|
2092 | Pretty print the object and display it through a pager. | |||
1965 |
|
2093 | |||
1966 | %page [options] OBJECT |
|
2094 | %page [options] OBJECT | |
1967 |
|
2095 | |||
@@ -1971,67 +2099,76 b' customizations.' | |||||
1971 |
|
2099 | |||
1972 | -r: page str(object), don't pretty-print it. |
|
2100 | -r: page str(object), don't pretty-print it. | |
1973 |
|
2101 | |||
|
2102 | **%pdb**:: | |||
1974 |
|
2103 | |||
1975 |
|
|
2104 | Control the automatic calling of the pdb interactive debugger. | |
1976 |
|
2105 | |||
1977 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without |
|
2106 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without | |
1978 | argument it works as a toggle. |
|
2107 | argument it works as a toggle. | |
1979 |
|
2108 | |||
1980 | When an exception is triggered, IPython can optionally call the |
|
2109 | When an exception is triggered, IPython can optionally call the | |
1981 |
|
|
2110 | interactive pdb debugger after the traceback printout. %pdb toggles | |
1982 |
|
|
2111 | this feature on and off. | |
1983 |
|
2112 | |||
1984 |
|
|
2113 | The initial state of this feature is set in your ipythonrc | |
1985 |
|
|
2114 | configuration file (the variable is called 'pdb'). | |
1986 |
|
2115 | |||
1987 | If you want to just activate the debugger AFTER an exception has fired, |
|
2116 | If you want to just activate the debugger AFTER an exception has fired, | |
1988 | without having to type '%pdb on' and rerunning your code, you can use |
|
2117 | without having to type '%pdb on' and rerunning your code, you can use | |
1989 | the %debug magic. |
|
2118 | the %debug magic. | |
1990 |
|
2119 | |||
|
2120 | **%pdef**:: | |||
1991 |
|
2121 | |||
1992 |
|
|
2122 | Print the definition header for any callable object. | |
1993 |
|
2123 | |||
1994 | If the object is a class, print the constructor information. |
|
2124 | If the object is a class, print the constructor information. | |
1995 |
|
2125 | |||
|
2126 | **%pdoc**:: | |||
1996 |
|
2127 | |||
1997 |
|
|
2128 | Print the docstring for an object. | |
1998 |
|
2129 | |||
1999 | If the given object is a class, it will print both the class and the |
|
2130 | If the given object is a class, it will print both the class and the | |
2000 | constructor docstrings. |
|
2131 | constructor docstrings. | |
2001 |
|
2132 | |||
|
2133 | **%pfile**:: | |||
2002 |
|
2134 | |||
2003 |
|
|
2135 | Print (or run through pager) the file where an object is defined. | |
2004 |
|
2136 | |||
2005 | The file opens at the line where the object definition begins. IPython |
|
2137 | The file opens at the line where the object definition begins. IPython | |
2006 |
|
|
2138 | will honor the environment variable PAGER if set, and otherwise will | |
2007 |
|
|
2139 | do its best to print the file in a convenient form. | |
2008 |
|
2140 | |||
2009 | If the given argument is not an object currently defined, IPython will |
|
2141 | If the given argument is not an object currently defined, IPython will | |
2010 | try to interpret it as a filename (automatically adding a .py extension |
|
2142 | try to interpret it as a filename (automatically adding a .py extension | |
2011 |
|
|
2143 | if needed). You can thus use %pfile as a syntax highlighting code | |
|
2144 | viewer. | |||
2012 |
|
2145 | |||
|
2146 | **%pinfo**:: | |||
2013 |
|
2147 | |||
2014 |
|
|
2148 | Provide detailed information about an object. | |
2015 |
|
2149 | |||
2016 | '%pinfo object' is just a synonym for object? or ?object. |
|
2150 | '%pinfo object' is just a synonym for object? or ?object. | |
2017 |
|
2151 | |||
|
2152 | **%popd**:: | |||
2018 |
|
2153 | |||
2019 |
|
|
2154 | Change to directory popped off the top of the stack. | |
2020 |
|
2155 | |||
|
2156 | **%profile**:: | |||
2021 |
|
2157 | |||
2022 |
|
|
2158 | Print your currently active IPyhton profile. | |
2023 |
|
2159 | |||
|
2160 | **%prun**:: | |||
2024 |
|
2161 | |||
2025 |
|
|
2162 | Run a statement through the python code profiler. | |
2026 |
|
2163 | |||
2027 | Usage: |
|
2164 | Usage:\ | |
2028 | %prun [options] statement |
|
2165 | %prun [options] statement | |
2029 |
|
2166 | |||
2030 | The given statement (which doesn't require quote marks) is run via the |
|
2167 | The given statement (which doesn't require quote marks) is run via the | |
2031 | python profiler in a manner similar to the profile.run() function. |
|
2168 | python profiler in a manner similar to the profile.run() function. | |
2032 |
|
|
2169 | Namespaces are internally managed to work correctly; profile.run | |
2033 |
|
|
2170 | cannot be used in IPython because it makes certain assumptions about | |
2034 |
|
|
2171 | namespaces which do not hold under IPython. | |
2035 |
|
2172 | |||
2036 | Options: |
|
2173 | Options: | |
2037 |
|
2174 | |||
@@ -2043,8 +2180,8 b' customizations.' | |||||
2043 |
|
2180 | |||
2044 | * An integer: only these many lines are printed. |
|
2181 | * An integer: only these many lines are printed. | |
2045 |
|
2182 | |||
2046 |
|
|
2183 | * A float (between 0 and 1): this fraction of the report is printed | |
2047 |
|
|
2184 | (for example, use a limit of 0.4 to see the topmost 40% only). | |
2048 |
|
2185 | |||
2049 | You can combine several limits with repeated use of the option. For |
|
2186 | You can combine several limits with repeated use of the option. For | |
2050 | example, '-l __init__ -l 5' will print only the topmost 5 lines of |
|
2187 | example, '-l __init__ -l 5' will print only the topmost 5 lines of | |
@@ -2065,108 +2202,118 b' customizations.' | |||||
2065 | secondary criteria when the there is equality in all keys selected |
|
2202 | secondary criteria when the there is equality in all keys selected | |
2066 | before them. |
|
2203 | before them. | |
2067 |
|
2204 | |||
2068 |
|
|
2205 | Abbreviations can be used for any key names, as long as the | |
2069 |
|
|
2206 | abbreviation is unambiguous. The following are the keys currently | |
2070 |
|
2207 | defined: | ||
2071 | Valid Arg Meaning |
|
2208 | ||
2072 | "calls" call count |
|
2209 | Valid Arg Meaning\ | |
2073 | "cumulative" cumulative time |
|
2210 | "calls" call count\ | |
2074 | "file" file name |
|
2211 | "cumulative" cumulative time\ | |
2075 | "module" file name |
|
2212 | "file" file name\ | |
2076 | "pcalls" primitive call count |
|
2213 | "module" file name\ | |
2077 | "line" line number |
|
2214 | "pcalls" primitive call count\ | |
2078 | "name" function name |
|
2215 | "line" line number\ | |
2079 | "nfl" name/file/line |
|
2216 | "name" function name\ | |
2080 | "stdname" standard name |
|
2217 | "nfl" name/file/line\ | |
|
2218 | "stdname" standard name\ | |||
2081 | "time" internal time |
|
2219 | "time" internal time | |
2082 |
|
2220 | |||
2083 |
|
|
2221 | Note that all sorts on statistics are in descending order (placing | |
2084 |
|
|
2222 | most time consuming items first), where as name, file, and line number | |
2085 | searches are in ascending order (i.e., alphabetical). The subtle |
|
2223 | searches are in ascending order (i.e., alphabetical). The subtle | |
2086 | distinction between "nfl" and "stdname" is that the standard name is a |
|
2224 | distinction between "nfl" and "stdname" is that the standard name is a | |
2087 |
|
|
2225 | sort of the name as printed, which means that the embedded line | |
2088 |
|
|
2226 | numbers get compared in an odd way. For example, lines 3, 20, and 40 | |
2089 |
|
|
2227 | would (if the file names were the same) appear in the string order | |
2090 |
|
|
2228 | "20" "3" and "40". In contrast, "nfl" does a numeric compare of the | |
2091 | fact, sort_stats("nfl") is the same as sort_stats("name", "file", "line"). |
|
2229 | line numbers. In fact, sort_stats("nfl") is the same as | |
|
2230 | sort_stats("name", "file", "line"). | |||
2092 |
|
2231 | |||
2093 |
|
|
2232 | -T <filename>: save profile results as shown on screen to a text | |
2094 |
|
|
2233 | file. The profile is still shown on screen. | |
2095 |
|
2234 | |||
2096 | -D <filename>: save (via dump_stats) profile statistics to given |
|
2235 | -D <filename>: save (via dump_stats) profile statistics to given | |
2097 | filename. This data is in a format understod by the pstats module, and |
|
2236 | filename. This data is in a format understod by the pstats module, and | |
2098 |
|
|
2237 | is generated by a call to the dump_stats() method of profile | |
2099 |
|
|
2238 | objects. The profile is still shown on screen. | |
2100 |
|
2239 | |||
2101 | If you want to run complete programs under the profiler's control, use |
|
2240 | If you want to run complete programs under the profiler's control, use | |
2102 | '%run -p [prof_opts] filename.py [args to program]' where prof_opts |
|
2241 | '%run -p [prof_opts] filename.py [args to program]' where prof_opts | |
2103 | contains profiler specific options as described here. |
|
2242 | contains profiler specific options as described here. | |
2104 |
|
2243 | |||
2105 |
|
|
2244 | You can read the complete documentation for the profile module with:\ | |
2106 | In [1]: import profile; profile.help() |
|
2245 | In [1]: import profile; profile.help() | |
2107 |
|
2246 | |||
|
2247 | **%psearch**:: | |||
2108 |
|
2248 | |||
2109 |
|
|
2249 | Search for object in namespaces by wildcard. | |
2110 |
|
2250 | |||
2111 | %psearch [options] PATTERN [OBJECT TYPE] |
|
2251 | %psearch [options] PATTERN [OBJECT TYPE] | |
2112 |
|
2252 | |||
2113 | Note: ? can be used as a synonym for %psearch, at the beginning or at |
|
2253 | Note: ? can be used as a synonym for %psearch, at the beginning or at | |
2114 | the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the |
|
2254 | the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the | |
2115 |
|
|
2255 | rest of the command line must be unchanged (options come first), so | |
2116 |
|
|
2256 | for example the following forms are equivalent | |
2117 |
|
2257 | |||
2118 | %psearch -i a* function -i a* function? ?-i a* function |
|
2258 | %psearch -i a* function | |
|
2259 | -i a* function? | |||
|
2260 | ?-i a* function | |||
2119 |
|
2261 | |||
2120 | Arguments: |
|
2262 | Arguments: | |
2121 |
|
2263 | |||
2122 | PATTERN |
|
2264 | PATTERN | |
2123 |
|
2265 | |||
2124 |
|
|
2266 | where PATTERN is a string containing * as a wildcard similar to its | |
2125 |
|
|
2267 | use in a shell. The pattern is matched in all namespaces on the | |
2126 |
|
|
2268 | search path. By default objects starting with a single _ are not | |
2127 | IPython generated objects have a single underscore. The default is case |
|
2269 | matched, many IPython generated objects have a single | |
2128 | insensitive matching. Matching is also done on the attributes of objects |
|
2270 | underscore. The default is case insensitive matching. Matching is | |
2129 | and not only on the objects in a module. |
|
2271 | also done on the attributes of objects and not only on the objects | |
|
2272 | in a module. | |||
2130 |
|
2273 | |||
2131 | [OBJECT TYPE] |
|
2274 | [OBJECT TYPE] | |
2132 |
|
2275 | |||
2133 |
|
|
2276 | Is the name of a python type from the types module. The name is | |
2134 |
|
|
2277 | given in lowercase without the ending type, ex. StringType is | |
2135 |
|
|
2278 | written string. By adding a type here only objects matching the | |
2136 | Using all here makes the pattern match all types (this is the default). |
|
2279 | given type are matched. Using all here makes the pattern match all | |
|
2280 | types (this is the default). | |||
2137 |
|
2281 | |||
2138 | Options: |
|
2282 | Options: | |
2139 |
|
2283 | |||
2140 |
|
|
2284 | -a: makes the pattern match even objects whose names start with a | |
2141 |
|
|
2285 | single underscore. These names are normally ommitted from the | |
|
2286 | search. | |||
2142 |
|
2287 | |||
2143 |
|
|
2288 | -i/-c: make the pattern case insensitive/sensitive. If neither of | |
2144 |
|
|
2289 | these options is given, the default is read from your ipythonrc | |
2145 | option name which sets this value is 'wildcards_case_sensitive'. If this |
|
2290 | file. The option name which sets this value is | |
2146 | option is not specified in your ipythonrc file, IPython's internal |
|
2291 | 'wildcards_case_sensitive'. If this option is not specified in your | |
2147 | default is to do a case sensitive search. |
|
2292 | ipythonrc file, IPython's internal default is to do a case sensitive | |
|
2293 | search. | |||
2148 |
|
2294 | |||
2149 | -e/-s NAMESPACE: exclude/search a given namespace. The pattern you |
|
2295 | -e/-s NAMESPACE: exclude/search a given namespace. The pattern you | |
2150 |
|
|
2296 | specifiy can be searched in any of the following namespaces: | |
2151 |
|
|
2297 | 'builtin', 'user', 'user_global','internal', 'alias', where | |
2152 |
|
|
2298 | 'builtin' and 'user' are the search defaults. Note that you should | |
2153 | specifying namespaces. |
|
2299 | not use quotes when specifying namespaces. | |
2154 |
|
|
2300 | ||
2155 |
|
|
2301 | 'Builtin' contains the python module builtin, 'user' contains all | |
2156 |
|
|
2302 | user data, 'alias' only contain the shell aliases and no python | |
2157 |
|
|
2303 | objects, 'internal' contains objects used by IPython. The | |
2158 | is only used by embedded IPython instances, and it contains module-level |
|
2304 | 'user_global' namespace is only used by embedded IPython instances, | |
2159 | globals. You can add namespaces to the search with -s or exclude them |
|
2305 | and it contains module-level globals. You can add namespaces to the | |
2160 | with -e (these options can be given more than once). |
|
2306 | search with -s or exclude them with -e (these options can be given | |
|
2307 | more than once). | |||
2161 |
|
2308 | |||
2162 | Examples: |
|
2309 | Examples: | |
2163 |
|
2310 | |||
2164 |
|
|
2311 | %psearch a* -> objects beginning with an a | |
2165 |
|
|
2312 | %psearch -e builtin a* -> objects NOT in the builtin space starting in a | |
2166 | all functions beginning with an a %psearch re.e* -> objects beginning |
|
2313 | %psearch a* function -> all functions beginning with an a | |
2167 | with an e in module re %psearch r*.e* -> objects that start with e in |
|
2314 | %psearch re.e* -> objects beginning with an e in module re | |
2168 | modules starting in r %psearch r*.* string -> all strings in modules |
|
2315 | %psearch r*.e* -> objects that start with e in modules starting in r | |
2169 | beginning with r |
|
2316 | %psearch r*.* string -> all strings in modules beginning with r | |
2170 |
|
2317 | |||
2171 | Case sensitve search: |
|
2318 | Case sensitve search: | |
2172 |
|
2319 | |||
@@ -2176,82 +2323,136 b' customizations.' | |||||
2176 |
|
2323 | |||
2177 | %psearch -a _* list objects beginning with a single underscore |
|
2324 | %psearch -a _* list objects beginning with a single underscore | |
2178 |
|
2325 | |||
|
2326 | **%psource**:: | |||
2179 |
|
2327 | |||
2180 |
|
|
2328 | Print (or run through pager) the source code for an object. | |
2181 |
|
2329 | |||
|
2330 | **%pushd**:: | |||
2182 |
|
2331 | |||
2183 |
|
|
2332 | Place the current dir on stack and change directory. | |
2184 |
|
2333 | |||
2185 | Usage: |
|
2334 | Usage:\ | |
2186 | %pushd ['dirname'] |
|
2335 | %pushd ['dirname'] | |
2187 |
|
2336 | |||
|
2337 | **%pwd**:: | |||
2188 |
|
2338 | |||
2189 |
|
|
2339 | Return the current working directory path. | |
2190 |
|
2340 | |||
|
2341 | **%pycat**:: | |||
2191 |
|
2342 | |||
2192 |
|
|
2343 | Show a syntax-highlighted file through a pager. | |
2193 |
|
2344 | |||
2194 |
|
|
2345 | This magic is similar to the cat utility, but it will assume the file | |
2195 |
|
|
2346 | to be Python source and will show it with syntax highlighting. | |
2196 |
|
2347 | |||
|
2348 | **%quickref**:: | |||
2197 |
|
2349 | |||
2198 |
|
|
2350 | Show a quick reference sheet | |
2199 |
|
2351 | |||
|
2352 | **%quit**:: | |||
2200 |
|
2353 | |||
2201 |
|
|
2354 | Exit IPython, confirming if configured to do so (like %exit) | |
2202 |
|
2355 | |||
|
2356 | **%r**:: | |||
2203 |
|
2357 | |||
2204 |
|
|
2358 | Repeat previous input. | |
2205 |
|
2359 | |||
2206 | Note: Consider using the more powerfull %rep instead! |
|
2360 | Note: Consider using the more powerfull %rep instead! | |
2207 |
|
2361 | |||
2208 |
|
|
2362 | If given an argument, repeats the previous command which starts with | |
2209 |
|
|
2363 | the same string, otherwise it just repeats the previous input. | |
|
2364 | ||||
|
2365 | Shell escaped commands (with ! as first character) are not recognized | |||
|
2366 | by this system, only pure python code and magic commands. | |||
2210 |
|
2367 | |||
2211 | Shell escaped commands (with ! as first character) are not recognized by |
|
2368 | **%rehashdir**:: | |
2212 | this system, only pure python code and magic commands. |
|
|||
2213 |
|
2369 | |||
|
2370 | Add executables in all specified dirs to alias table | |||
2214 |
|
2371 | |||
2215 | %rehashx: Update the alias table with all executable files in $PATH. |
|
2372 | Usage: | |
2216 |
|
2373 | |||
2217 | This version explicitly checks that every entry in $PATH is a file with |
|
2374 | %rehashdir c:/bin;c:/tools | |
2218 | execute access (os.X_OK), so it is much slower than %rehash. |
|
2375 | - Add all executables under c:/bin and c:/tools to alias table, in | |
|
2376 | order to make them directly executable from any directory. | |||
2219 |
|
2377 | |||
2220 | Under Windows, it checks executability as a match agains a ``|``-separated |
|
2378 | Without arguments, add all executables in current directory. | |
2221 | string of extensions, stored in the IPython config variable |
|
2379 | ||
2222 | win_exec_ext. This defaults to ``exe|com|bat``. |
|
2380 | **%rehashx**:: | |
|
2381 | ||||
|
2382 | Update the alias table with all executable files in $PATH. | |||
|
2383 | ||||
|
2384 | This version explicitly checks that every entry in $PATH is a file | |||
|
2385 | with execute access (os.X_OK), so it is much slower than %rehash. | |||
|
2386 | ||||
|
2387 | Under Windows, it checks executability as a match agains a | |||
|
2388 | '|'-separated string of extensions, stored in the IPython config | |||
|
2389 | variable win_exec_ext. This defaults to 'exe|com|bat'. | |||
2223 |
|
2390 | |||
2224 | This function also resets the root module cache of module completer, |
|
2391 | This function also resets the root module cache of module completer, | |
2225 | used on slow filesystems. |
|
2392 | used on slow filesystems. | |
2226 |
|
2393 | |||
|
2394 | **%rep**:: | |||
|
2395 | ||||
|
2396 | Repeat a command, or get command to input line for editing | |||
|
2397 | ||||
|
2398 | - %rep (no arguments): | |||
|
2399 | ||||
|
2400 | Place a string version of last computation result (stored in the special '_' | |||
|
2401 | variable) to the next input prompt. Allows you to create elaborate command | |||
|
2402 | lines without using copy-paste:: | |||
|
2403 | ||||
|
2404 | $ l = ["hei", "vaan"] | |||
|
2405 | $ "".join(l) | |||
|
2406 | ==> heivaan | |||
|
2407 | $ %rep | |||
|
2408 | $ heivaan_ <== cursor blinking | |||
|
2409 | ||||
|
2410 | %rep 45 | |||
|
2411 | ||||
|
2412 | Place history line 45 to next input prompt. Use %hist to find out the | |||
|
2413 | number. | |||
|
2414 | ||||
|
2415 | %rep 1-4 6-7 3 | |||
|
2416 | ||||
|
2417 | Repeat the specified lines immediately. Input slice syntax is the same as | |||
|
2418 | in %macro and %save. | |||
|
2419 | ||||
|
2420 | %rep foo | |||
2227 |
|
2421 | |||
2228 | %reset: Resets the namespace by removing all names defined by the user. |
|
2422 | Place the most recent line that has the substring "foo" to next input. | |
|
2423 | (e.g. 'svn ci -m foobar'). | |||
|
2424 | ||||
|
2425 | **%reset**:: | |||
|
2426 | ||||
|
2427 | Resets the namespace by removing all names defined by the user. | |||
2229 |
|
2428 | |||
2230 | Input/Output history are left around in case you need them. |
|
2429 | Input/Output history are left around in case you need them. | |
2231 |
|
2430 | |||
|
2431 | **%run**:: | |||
2232 |
|
2432 | |||
2233 |
|
|
2433 | Run the named file inside IPython as a program. | |
2234 |
|
2434 | |||
2235 | Usage: |
|
2435 | Usage:\ | |
2236 | %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args] |
|
2436 | %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args] | |
2237 |
|
2437 | |||
2238 | Parameters after the filename are passed as command-line arguments to |
|
2438 | Parameters after the filename are passed as command-line arguments to | |
2239 |
|
|
2439 | the program (put in sys.argv). Then, control returns to IPython's | |
|
2440 | prompt. | |||
2240 |
|
2441 | |||
2241 |
|
|
2442 | This is similar to running at a system prompt:\ | |
2242 |
|
|
2443 | $ python file args\ | |
2243 | but with the advantage of giving you IPython's tracebacks, and of |
|
2444 | but with the advantage of giving you IPython's tracebacks, and of | |
2244 | loading all variables into your interactive namespace for further use |
|
2445 | loading all variables into your interactive namespace for further use | |
2245 | (unless -p is used, see below). |
|
2446 | (unless -p is used, see below). | |
2246 |
|
2447 | |||
2247 | The file is executed in a namespace initially consisting only of |
|
2448 | The file is executed in a namespace initially consisting only of | |
2248 |
|
|
2449 | __name__=='__main__' and sys.argv constructed as indicated. It thus | |
2249 |
|
|
2450 | sees its environment as if it were being run as a stand-alone program | |
2250 |
|
|
2451 | (except for sharing global objects such as previously imported | |
2251 |
|
|
2452 | modules). But after execution, the IPython interactive namespace gets | |
2252 |
|
|
2453 | updated with all variables defined in the program (except for __name__ | |
2253 |
|
|
2454 | and sys.argv). This allows for very convenient loading of code for | |
2254 |
|
|
2455 | interactive work, while giving each program a 'clean sheet' to run in. | |
2255 |
|
2456 | |||
2256 | Options: |
|
2457 | Options: | |
2257 |
|
2458 | |||
@@ -2260,45 +2461,45 b' customizations.' | |||||
2260 | scripts and reloading the definitions in them without calling code |
|
2461 | scripts and reloading the definitions in them without calling code | |
2261 | protected by an ' if __name__ == "__main__" ' clause. |
|
2462 | protected by an ' if __name__ == "__main__" ' clause. | |
2262 |
|
2463 | |||
2263 |
|
|
2464 | -i: run the file in IPython's namespace instead of an empty one. This | |
2264 |
|
|
2465 | is useful if you are experimenting with code written in a text editor | |
2265 |
|
|
2466 | which depends on variables defined interactively. | |
2266 |
|
2467 | |||
2267 |
|
|
2468 | -e: ignore sys.exit() calls or SystemExit exceptions in the script | |
2268 |
|
|
2469 | being run. This is particularly useful if IPython is being used to | |
2269 |
|
|
2470 | run unittests, which always exit with a sys.exit() call. In such | |
2270 |
|
|
2471 | cases you are interested in the output of the test results, not in | |
2271 |
|
|
2472 | seeing a traceback of the unittest module. | |
2272 |
|
2473 | |||
2273 | -t: print timing information at the end of the run. IPython will give |
|
2474 | -t: print timing information at the end of the run. IPython will give | |
2274 |
|
|
2475 | you an estimated CPU time consumption for your script, which under | |
2275 |
|
|
2476 | Unix uses the resource module to avoid the wraparound problems of | |
2276 |
|
|
2477 | time.clock(). Under Unix, an estimate of time spent on system tasks | |
2277 |
|
|
2478 | is also given (for Windows platforms this is reported as 0.0). | |
2278 |
|
2479 | |||
2279 |
|
|
2480 | If -t is given, an additional -N<N> option can be given, where <N> | |
2280 |
|
|
2481 | must be an integer indicating how many times you want the script to | |
2281 |
|
|
2482 | run. The final timing report will include total and per run results. | |
2282 |
|
2483 | |||
2283 | For example (testing the script uniq_stable.py): |
|
2484 | For example (testing the script uniq_stable.py): | |
2284 |
|
2485 | |||
2285 | In [1]: run -t uniq_stable |
|
2486 | In [1]: run -t uniq_stable | |
2286 |
|
2487 | |||
2287 |
|
|
2488 | IPython CPU timings (estimated):\ | |
2288 |
|
|
2489 | User : 0.19597 s.\ | |
2289 | System: 0.0 s. |
|
2490 | System: 0.0 s.\ | |
2290 |
|
2491 | |||
2291 | In [2]: run -t -N5 uniq_stable |
|
2492 | In [2]: run -t -N5 uniq_stable | |
2292 |
|
2493 | |||
2293 |
|
|
2494 | IPython CPU timings (estimated):\ | |
2294 |
|
|
2495 | Total runs performed: 5\ | |
2295 |
|
|
2496 | Times : Total Per run\ | |
2296 |
|
|
2497 | User : 0.910862 s, 0.1821724 s.\ | |
2297 | System: 0.0 s, 0.0 s. |
|
2498 | System: 0.0 s, 0.0 s. | |
2298 |
|
2499 | |||
2299 |
|
|
2500 | -d: run your program under the control of pdb, the Python debugger. | |
2300 |
|
|
2501 | This allows you to execute your program step by step, watch variables, | |
2301 |
|
|
2502 | etc. Internally, what IPython does is similar to calling: | |
2302 |
|
2503 | |||
2303 | pdb.run('execfile("YOURFILENAME")') |
|
2504 | pdb.run('execfile("YOURFILENAME")') | |
2304 |
|
2505 | |||
@@ -2308,17 +2509,17 b' customizations.' | |||||
2308 |
|
2509 | |||
2309 | %run -d -b40 myscript |
|
2510 | %run -d -b40 myscript | |
2310 |
|
2511 | |||
2311 |
|
|
2512 | will set the first breakpoint at line 40 in myscript.py. Note that | |
2312 |
|
|
2513 | the first breakpoint must be set on a line which actually does | |
2313 |
|
|
2514 | something (not a comment or docstring) for it to stop execution. | |
2314 |
|
2515 | |||
2315 | When the pdb debugger starts, you will see a (Pdb) prompt. You must |
|
2516 | When the pdb debugger starts, you will see a (Pdb) prompt. You must | |
2316 | first enter 'c' (without qoutes) to start execution up to the first |
|
2517 | first enter 'c' (without qoutes) to start execution up to the first | |
2317 | breakpoint. |
|
2518 | breakpoint. | |
2318 |
|
2519 | |||
2319 |
|
|
2520 | Entering 'help' gives information about the use of the debugger. You | |
2320 |
|
|
2521 | can easily see pdb's full documentation with "import pdb;pdb.help()" | |
2321 | prompt. |
|
2522 | at a prompt. | |
2322 |
|
2523 | |||
2323 | -p: run program under the control of the Python profiler module (which |
|
2524 | -p: run program under the control of the Python profiler module (which | |
2324 | prints a detailed report of execution times, function calls, etc). |
|
2525 | prints a detailed report of execution times, function calls, etc). | |
@@ -2333,37 +2534,39 b' customizations.' | |||||
2333 | Internally this triggers a call to %prun, see its documentation for |
|
2534 | Internally this triggers a call to %prun, see its documentation for | |
2334 | details on the options available specifically for profiling. |
|
2535 | details on the options available specifically for profiling. | |
2335 |
|
2536 | |||
2336 |
|
|
2537 | There is one special usage for which the text above doesn't apply: | |
2337 |
|
|
2538 | if the filename ends with .ipy, the file is run as ipython script, | |
2338 |
|
|
2539 | just as if the commands were written on IPython prompt. | |
2339 |
|
2540 | |||
|
2541 | **%runlog**:: | |||
2340 |
|
2542 | |||
2341 |
|
|
2543 | Run files as logs. | |
2342 |
|
2544 | |||
2343 | Usage: |
|
2545 | Usage:\ | |
2344 | %runlog file1 file2 ... |
|
2546 | %runlog file1 file2 ... | |
2345 |
|
2547 | |||
2346 |
|
|
2548 | Run the named files (treating them as log files) in sequence inside | |
2347 |
|
|
2549 | the interpreter, and return to the prompt. This is much slower than | |
2348 |
|
|
2550 | %run because each line is executed in a try/except block, but it | |
2349 |
|
|
2551 | allows running files with syntax errors in them. | |
2350 |
|
2552 | |||
2351 | Normally IPython will guess when a file is one of its own logfiles, so |
|
2553 | Normally IPython will guess when a file is one of its own logfiles, so | |
2352 | you can typically use %run even for logs. This shorthand allows you to |
|
2554 | you can typically use %run even for logs. This shorthand allows you to | |
2353 | force any file to be treated as a log file. |
|
2555 | force any file to be treated as a log file. | |
2354 |
|
2556 | |||
|
2557 | **%save**:: | |||
2355 |
|
2558 | |||
2356 |
|
|
2559 | Save a set of lines to a given filename. | |
2357 |
|
2560 | |||
2358 | Usage: |
|
2561 | Usage:\ | |
2359 | %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ... |
|
2562 | %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ... | |
2360 |
|
2563 | |||
2361 | Options: |
|
2564 | Options: | |
2362 |
|
2565 | |||
2363 |
|
|
2566 | -r: use 'raw' input. By default, the 'processed' history is used, | |
2364 |
|
|
2567 | so that magics are loaded in their transformed version to valid | |
2365 |
|
|
2568 | Python. If this option is given, the raw input as typed as the | |
2366 | instead. |
|
2569 | command line is used instead. | |
2367 |
|
2570 | |||
2368 | This function uses the same syntax as %macro for line extraction, but |
|
2571 | This function uses the same syntax as %macro for line extraction, but | |
2369 | instead of creating a macro it saves the resulting string to the |
|
2572 | instead of creating a macro it saves the resulting string to the | |
@@ -2372,25 +2575,28 b' customizations.' | |||||
2372 | It adds a '.py' extension to the file if you don't do so yourself, and |
|
2575 | It adds a '.py' extension to the file if you don't do so yourself, and | |
2373 | it asks for confirmation before overwriting existing files. |
|
2576 | it asks for confirmation before overwriting existing files. | |
2374 |
|
2577 | |||
|
2578 | **%sc**:: | |||
2375 |
|
2579 | |||
2376 |
|
|
2580 | Shell capture - execute a shell command and capture its output. | |
2377 |
|
2581 | |||
2378 | DEPRECATED. Suboptimal, retained for backwards compatibility. |
|
2582 | DEPRECATED. Suboptimal, retained for backwards compatibility. | |
2379 |
|
2583 | |||
2380 | You should use the form 'var = !command' instead. Example: |
|
2584 | You should use the form 'var = !command' instead. Example: | |
2381 |
|
2585 | |||
2382 |
|
|
2586 | "%sc -l myfiles = ls ~" should now be written as | |
2383 |
|
2587 | |||
2384 |
|
|
2588 | "myfiles = !ls ~" | |
2385 |
|
2589 | |||
2386 |
|
|
2590 | myfiles.s, myfiles.l and myfiles.n still apply as documented | |
|
2591 | below. | |||
2387 |
|
2592 | |||
2388 | - %sc [options] varname=command |
|
2593 | -- | |
|
2594 | %sc [options] varname=command | |||
2389 |
|
2595 | |||
2390 |
|
|
2596 | IPython will run the given command using commands.getoutput(), and | |
2391 |
|
|
2597 | will then update the user's interactive namespace with a variable | |
2392 |
|
|
2598 | called varname, containing the value of the call. Your command can | |
2393 |
|
|
2599 | contain shell wildcards, pipes, etc. | |
2394 |
|
2600 | |||
2395 | The '=' sign in the syntax is mandatory, and the variable name you |
|
2601 | The '=' sign in the syntax is mandatory, and the variable name you | |
2396 | supply must follow Python's standard conventions for valid names. |
|
2602 | supply must follow Python's standard conventions for valid names. | |
@@ -2400,133 +2606,202 b' customizations.' | |||||
2400 | Options: |
|
2606 | Options: | |
2401 |
|
2607 | |||
2402 | -l: list output. Split the output on newlines into a list before |
|
2608 | -l: list output. Split the output on newlines into a list before | |
2403 |
|
|
2609 | assigning it to the given variable. By default the output is stored | |
2404 |
|
|
2610 | as a single string. | |
2405 |
|
2611 | |||
2406 | -v: verbose. Print the contents of the variable. |
|
2612 | -v: verbose. Print the contents of the variable. | |
2407 |
|
2613 | |||
2408 | In most cases you should not need to split as a list, because the |
|
2614 | In most cases you should not need to split as a list, because the | |
2409 | returned value is a special type of string which can automatically |
|
2615 | returned value is a special type of string which can automatically | |
2410 | provide its contents either as a list (split on newlines) or as a |
|
2616 | provide its contents either as a list (split on newlines) or as a | |
2411 |
|
|
2617 | space-separated string. These are convenient, respectively, either | |
2412 |
|
|
2618 | for sequential processing or to be passed to a shell command. | |
2413 |
|
2619 | |||
2414 | For example: |
|
2620 | For example: | |
2415 |
|
2621 | |||
2416 |
|
|
2622 | # Capture into variable a | |
|
2623 | In [9]: sc a=ls *py | |||
2417 |
|
2624 | |||
2418 |
|
|
2625 | # a is a string with embedded newlines | |
2419 | win32_manual_post_install.py' |
|
2626 | In [10]: a | |
|
2627 | Out[10]: 'setup.py win32_manual_post_install.py' | |||
2420 |
|
2628 | |||
2421 | # which can be seen as a list: In [11]: a.l Out[11]: ['setup.py', |
|
2629 | # which can be seen as a list: | |
2422 | 'win32_manual_post_install.py'] |
|
2630 | In [11]: a.l | |
|
2631 | Out[11]: ['setup.py', 'win32_manual_post_install.py'] | |||
2423 |
|
2632 | |||
2424 |
|
|
2633 | # or as a whitespace-separated string: | |
2425 | win32_manual_post_install.py' |
|
2634 | In [12]: a.s | |
|
2635 | Out[12]: 'setup.py win32_manual_post_install.py' | |||
2426 |
|
2636 | |||
2427 |
|
|
2637 | # a.s is useful to pass as a single command line: | |
2428 | 146 setup.py 130 win32_manual_post_install.py 276 total |
|
2638 | In [13]: !wc -l $a.s | |
|
2639 | 146 setup.py | |||
|
2640 | 130 win32_manual_post_install.py | |||
|
2641 | 276 total | |||
2429 |
|
2642 | |||
2430 |
|
|
2643 | # while the list form is useful to loop over: | |
2431 | ....: !wc -l $f ....: 146 setup.py 130 win32_manual_post_install.py |
|
2644 | In [14]: for f in a.l: | |
|
2645 | ....: !wc -l $f | |||
|
2646 | ....: | |||
|
2647 | 146 setup.py | |||
|
2648 | 130 win32_manual_post_install.py | |||
2432 |
|
2649 | |||
2433 |
|
|
2650 | Similiarly, the lists returned by the -l option are also special, in | |
2434 |
|
|
2651 | the sense that you can equally invoke the .s attribute on them to | |
2435 | automatically get a whitespace-separated string from their contents: |
|
2652 | automatically get a whitespace-separated string from their contents: | |
2436 |
|
2653 | |||
2437 | In [1]: sc -l b=ls *py |
|
2654 | In [1]: sc -l b=ls *py | |
2438 |
|
2655 | |||
2439 | In [2]: b Out[2]: ['setup.py', 'win32_manual_post_install.py'] |
|
2656 | In [2]: b | |
|
2657 | Out[2]: ['setup.py', 'win32_manual_post_install.py'] | |||
|
2658 | ||||
|
2659 | In [3]: b.s | |||
|
2660 | Out[3]: 'setup.py win32_manual_post_install.py' | |||
|
2661 | ||||
|
2662 | In summary, both the lists and strings used for ouptut capture have | |||
|
2663 | the following special attributes: | |||
|
2664 | ||||
|
2665 | .l (or .list) : value as list. | |||
|
2666 | .n (or .nlstr): value as newline-separated string. | |||
|
2667 | .s (or .spstr): value as space-separated string. | |||
2440 |
|
2668 | |||
2441 | In [3]: b.s Out[3]: 'setup.py win32_manual_post_install.py' |
|
2669 | **%store**:: | |
2442 |
|
2670 | |||
2443 | In summary, both the lists and strings used for ouptut capture have the |
|
2671 | Lightweight persistence for python variables. | |
2444 | following special attributes: |
|
|||
2445 |
|
2672 | |||
2446 | .l (or .list) : value as list. .n (or .nlstr): value as |
|
2673 | Example: | |
2447 | newline-separated string. .s (or .spstr): value as space-separated string. |
|
|||
2448 |
|
2674 | |||
|
2675 | ville@badger[~]|1> A = ['hello',10,'world']\ | |||
|
2676 | ville@badger[~]|2> %store A\ | |||
|
2677 | ville@badger[~]|3> Exit | |||
2449 |
|
2678 | |||
2450 | %sx: Shell execute - run a shell command and capture its output. |
|
2679 | (IPython session is closed and started again...) | |
|
2680 | ||||
|
2681 | ville@badger:~$ ipython -p pysh\ | |||
|
2682 | ville@badger[~]|1> print A | |||
|
2683 | ||||
|
2684 | ['hello', 10, 'world'] | |||
|
2685 | ||||
|
2686 | Usage: | |||
|
2687 | ||||
|
2688 | %store - Show list of all variables and their current values\ | |||
|
2689 | %store <var> - Store the *current* value of the variable to disk\ | |||
|
2690 | %store -d <var> - Remove the variable and its value from storage\ | |||
|
2691 | %store -z - Remove all variables from storage\ | |||
|
2692 | %store -r - Refresh all variables from store (delete current vals)\ | |||
|
2693 | %store foo >a.txt - Store value of foo to new file a.txt\ | |||
|
2694 | %store foo >>a.txt - Append value of foo to file a.txt\ | |||
|
2695 | ||||
|
2696 | It should be noted that if you change the value of a variable, you | |||
|
2697 | need to %store it again if you want to persist the new value. | |||
|
2698 | ||||
|
2699 | Note also that the variables will need to be pickleable; most basic | |||
|
2700 | python types can be safely %stored. | |||
|
2701 | ||||
|
2702 | Also aliases can be %store'd across sessions. | |||
|
2703 | ||||
|
2704 | **%sx**:: | |||
|
2705 | ||||
|
2706 | Shell execute - run a shell command and capture its output. | |||
2451 |
|
2707 | |||
2452 | %sx command |
|
2708 | %sx command | |
2453 |
|
2709 | |||
2454 | IPython will run the given command using commands.getoutput(), and |
|
2710 | IPython will run the given command using commands.getoutput(), and | |
2455 |
|
|
2711 | return the result formatted as a list (split on '\n'). Since the | |
2456 |
|
|
2712 | output is _returned_, it will be stored in ipython's regular output | |
2457 |
|
|
2713 | cache Out[N] and in the '_N' automatic variables. | |
2458 |
|
2714 | |||
2459 | Notes: |
|
2715 | Notes: | |
2460 |
|
2716 | |||
2461 |
|
|
2717 | 1) If an input line begins with '!!', then %sx is automatically | |
2462 | That is, while: !ls causes ipython to simply issue system('ls'), typing |
|
2718 | invoked. That is, while: | |
2463 | !!ls is a shorthand equivalent to: %sx ls |
|
2719 | !ls | |
|
2720 | causes ipython to simply issue system('ls'), typing | |||
|
2721 | !!ls | |||
|
2722 | is a shorthand equivalent to: | |||
|
2723 | %sx ls | |||
2464 |
|
2724 | |||
2465 | 2) %sx differs from %sc in that %sx automatically splits into a list, |
|
2725 | 2) %sx differs from %sc in that %sx automatically splits into a list, | |
2466 |
|
|
2726 | like '%sc -l'. The reason for this is to make it as easy as possible | |
2467 |
|
|
2727 | to process line-oriented shell output via further python commands. | |
2468 |
|
|
2728 | %sc is meant to provide much finer control, but requires more | |
|
2729 | typing. | |||
2469 |
|
2730 | |||
2470 | 3) Just like %sc -l, this is a list with special attributes: |
|
2731 | 3) Just like %sc -l, this is a list with special attributes: | |
2471 |
|
2732 | |||
2472 |
|
|
2733 | .l (or .list) : value as list. | |
2473 | newline-separated string. .s (or .spstr): value as whitespace-separated |
|
2734 | .n (or .nlstr): value as newline-separated string. | |
2474 | string. |
|
2735 | .s (or .spstr): value as whitespace-separated string. | |
2475 |
|
2736 | |||
2476 |
|
|
2737 | This is very useful when trying to use such lists as arguments to | |
2477 | commands. |
|
2738 | system commands. | |
2478 |
|
2739 | |||
|
2740 | **%system_verbose**:: | |||
2479 |
|
2741 | |||
2480 |
|
|
2742 | Set verbose printing of system calls. | |
2481 |
|
2743 | |||
2482 | If called without an argument, act as a toggle |
|
2744 | If called without an argument, act as a toggle | |
2483 |
|
2745 | |||
|
2746 | **%time**:: | |||
2484 |
|
2747 | |||
2485 |
|
|
2748 | Time execution of a Python statement or expression. | |
2486 |
|
2749 | |||
2487 | The CPU and wall clock times are printed, and the value of the |
|
2750 | The CPU and wall clock times are printed, and the value of the | |
2488 |
|
|
2751 | expression (if any) is returned. Note that under Win32, system time | |
2489 |
|
|
2752 | is always reported as 0, since it can not be measured. | |
2490 |
|
2753 | |||
2491 |
|
|
2754 | This function provides very basic timing functionality. In Python | |
2492 |
|
|
2755 | 2.3, the timeit module offers more control and sophistication, so this | |
2493 |
|
|
2756 | could be rewritten to use it (patches welcome). | |
2494 |
|
2757 | |||
2495 | Some examples: |
|
2758 | Some examples: | |
2496 |
|
2759 | |||
2497 | In [1]: time 2**128 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
2760 | In [1]: time 2**128 | |
2498 | Wall time: 0.00 Out[1]: 340282366920938463463374607431768211456L |
|
2761 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s | |
|
2762 | Wall time: 0.00 | |||
|
2763 | Out[1]: 340282366920938463463374607431768211456L | |||
2499 |
|
2764 | |||
2500 | In [2]: n = 1000000 |
|
2765 | In [2]: n = 1000000 | |
2501 |
|
2766 | |||
2502 | In [3]: time sum(range(n)) CPU times: user 1.20 s, sys: 0.05 s, total: |
|
2767 | In [3]: time sum(range(n)) | |
2503 | 1.25 s Wall time: 1.37 Out[3]: 499999500000L |
|
2768 | CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s | |
|
2769 | Wall time: 1.37 | |||
|
2770 | Out[3]: 499999500000L | |||
2504 |
|
2771 | |||
2505 | In [4]: time print 'hello world' hello world CPU times: user 0.00 s, |
|
2772 | In [4]: time print 'hello world' | |
2506 | sys: 0.00 s, total: 0.00 s Wall time: 0.00 |
|
2773 | hello world | |
|
2774 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s | |||
|
2775 | Wall time: 0.00 | |||
2507 |
|
2776 | |||
2508 |
|
|
2777 | Note that the time needed by Python to compile the given expression | |
2509 |
|
|
2778 | will be reported if it is more than 0.1s. In this example, the | |
2510 |
|
|
2779 | actual exponentiation is done by Python at compilation time, so while | |
2511 |
|
|
2780 | the expression can take a noticeable amount of time to compute, that | |
2512 |
|
|
2781 | time is purely due to the compilation: | |
2513 |
|
2782 | |||
2514 | In [5]: time 3**9999; CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
2783 | In [5]: time 3**9999; | |
|
2784 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s | |||
2515 | Wall time: 0.00 s |
|
2785 | Wall time: 0.00 s | |
2516 |
|
2786 | |||
2517 | In [6]: time 3**999999; CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 |
|
2787 | In [6]: time 3**999999; | |
2518 | s Wall time: 0.00 s Compiler : 0.78 s |
|
2788 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s | |
|
2789 | Wall time: 0.00 s | |||
|
2790 | Compiler : 0.78 s | |||
2519 |
|
2791 | |||
|
2792 | **%timeit**:: | |||
2520 |
|
2793 | |||
2521 |
|
|
2794 | Time execution of a Python statement or expression | |
2522 |
|
2795 | |||
2523 | Usage: |
|
2796 | Usage:\ | |
2524 | %timeit [-n<N> -r<R> [-t|-c]] statement |
|
2797 | %timeit [-n<N> -r<R> [-t|-c]] statement | |
2525 |
|
2798 | |||
2526 |
|
|
2799 | Time execution of a Python statement or expression using the timeit | |
|
2800 | module. | |||
2527 |
|
2801 | |||
2528 | Options: -n<N>: execute the given statement <N> times in a loop. If this |
|
2802 | Options: | |
2529 | value is not given, a fitting value is chosen. |
|
2803 | -n<N>: execute the given statement <N> times in a loop. If this value | |
|
2804 | is not given, a fitting value is chosen. | |||
2530 |
|
2805 | |||
2531 | -r<R>: repeat the loop iteration <R> times and take the best result. |
|
2806 | -r<R>: repeat the loop iteration <R> times and take the best result. | |
2532 | Default: 3 |
|
2807 | Default: 3 | |
@@ -2534,49 +2809,84 b' customizations.' | |||||
2534 | -t: use time.time to measure the time, which is the default on Unix. |
|
2809 | -t: use time.time to measure the time, which is the default on Unix. | |
2535 | This function measures wall time. |
|
2810 | This function measures wall time. | |
2536 |
|
2811 | |||
2537 |
|
|
2812 | -c: use time.clock to measure the time, which is the default on | |
2538 |
|
|
2813 | Windows and measures wall time. On Unix, resource.getrusage is used | |
2539 |
|
|
2814 | instead and returns the CPU user time. | |
2540 |
|
2815 | |||
2541 | -p<P>: use a precision of <P> digits to display the timing result. |
|
2816 | -p<P>: use a precision of <P> digits to display the timing result. | |
2542 | Default: 3 |
|
2817 | Default: 3 | |
2543 |
|
2818 | |||
2544 | Examples: |
|
2819 | ||
2545 | In [1]: %timeit pass 10000000 loops, best of 3: 53.3 ns per loop |
|
2820 | Examples:\ | |
|
2821 | In [1]: %timeit pass | |||
|
2822 | 10000000 loops, best of 3: 53.3 ns per loop | |||
2546 |
|
2823 | |||
2547 | In [2]: u = None |
|
2824 | In [2]: u = None | |
2548 |
|
2825 | |||
2549 | In [3]: %timeit u is None 10000000 loops, best of 3: 184 ns per loop |
|
2826 | In [3]: %timeit u is None | |
|
2827 | 10000000 loops, best of 3: 184 ns per loop | |||
2550 |
|
2828 | |||
2551 | In [4]: %timeit -r 4 u == None 1000000 loops, best of 4: 242 ns per loop |
|
2829 | In [4]: %timeit -r 4 u == None | |
|
2830 | 1000000 loops, best of 4: 242 ns per loop | |||
2552 |
|
2831 | |||
2553 | In [5]: import time |
|
2832 | In [5]: import time | |
2554 |
|
2833 | |||
2555 |
|
|
2834 | In [6]: %timeit -n1 time.sleep(2) | |
|
2835 | 1 loops, best of 3: 2 s per loop | |||
|
2836 | ||||
2556 |
|
2837 | |||
2557 | The times reported by %timeit will be slightly higher than those |
|
2838 | The times reported by %timeit will be slightly higher than those | |
2558 | reported by the timeit.py script when variables are accessed. This is |
|
2839 | reported by the timeit.py script when variables are accessed. This is | |
2559 |
|
|
2840 | due to the fact that %timeit executes the statement in the namespace | |
2560 |
|
|
2841 | of the shell, compared with timeit.py, which uses a single setup | |
2561 |
|
|
2842 | statement to import function or create variables. Generally, the bias | |
2562 |
|
|
2843 | does not matter as long as results from timeit.py are not mixed with | |
2563 | %timeit. |
|
2844 | those from %timeit. | |
|
2845 | ||||
|
2846 | **%unalias**:: | |||
|
2847 | ||||
|
2848 | Remove an alias | |||
|
2849 | ||||
|
2850 | **%upgrade**:: | |||
|
2851 | ||||
|
2852 | Upgrade your IPython installation | |||
|
2853 | ||||
|
2854 | This will copy the config files that don't yet exist in your | |||
|
2855 | ipython dir from the system config dir. Use this after upgrading | |||
|
2856 | IPython if you don't wish to delete your .ipython dir. | |||
|
2857 | ||||
|
2858 | Call with -nolegacy to get rid of ipythonrc* files (recommended for | |||
|
2859 | new users) | |||
|
2860 | ||||
|
2861 | **%which**:: | |||
2564 |
|
2862 | |||
|
2863 | %which <cmd> => search PATH for files matching cmd. Also scans aliases. | |||
2565 |
|
2864 | |||
2566 | %unalias: Remove an alias |
|
2865 | Traverses PATH and prints all files (not just executables!) that match the | |
|
2866 | pattern on command line. Probably more useful in finding stuff | |||
|
2867 | interactively than 'which', which only prints the first matching item. | |||
2567 |
|
2868 | |||
|
2869 | Also discovers and expands aliases, so you'll see what will be executed | |||
|
2870 | when you call an alias. | |||
2568 |
|
2871 | |||
2569 | %upgrade: Upgrade your IPython installation |
|
2872 | Example: | |
2570 |
|
2873 | |||
2571 | This will copy the config files that don't yet exist in your ipython dir |
|
2874 | [~]|62> %which d | |
2572 | from the system config dir. Use this after upgrading IPython if you |
|
2875 | d -> ls -F --color=auto | |
2573 | don't wish to delete your .ipython dir. |
|
2876 | == c:\cygwin\bin\ls.exe | |
|
2877 | c:\cygwin\bin\d.exe | |||
2574 |
|
2878 | |||
2575 | Call with -nolegacy to get rid of ipythonrc* files (recommended for new |
|
2879 | [~]|64> %which diff* | |
2576 | users) |
|
2880 | diff3 -> diff3 | |
|
2881 | == c:\cygwin\bin\diff3.exe | |||
|
2882 | diff -> diff | |||
|
2883 | == c:\cygwin\bin\diff.exe | |||
|
2884 | c:\cygwin\bin\diff.exe | |||
|
2885 | c:\cygwin\bin\diff3.exe | |||
2577 |
|
2886 | |||
|
2887 | **%who**:: | |||
2578 |
|
2888 | |||
2579 |
|
|
2889 | Print all interactive variables, with some minimal formatting. | |
2580 |
|
2890 | |||
2581 | If any arguments are given, only variables whose type matches one of |
|
2891 | If any arguments are given, only variables whose type matches one of | |
2582 | these are printed. For example: |
|
2892 | these are printed. For example: | |
@@ -2587,7 +2897,7 b' customizations.' | |||||
2587 | variables. To find the proper type names, simply use type(var) at a |
|
2897 | variables. To find the proper type names, simply use type(var) at a | |
2588 | command line to see how python prints type names. For example: |
|
2898 | command line to see how python prints type names. For example: | |
2589 |
|
2899 | |||
2590 |
|
|
2900 | In [1]: type('hello')\ | |
2591 | Out[1]: <type 'str'> |
|
2901 | Out[1]: <type 'str'> | |
2592 |
|
2902 | |||
2593 | indicates that the type name for strings is 'str'. |
|
2903 | indicates that the type name for strings is 'str'. | |
@@ -2598,34 +2908,38 b' customizations.' | |||||
2598 | This is deliberate, as typically you may load many modules and the |
|
2908 | This is deliberate, as typically you may load many modules and the | |
2599 | purpose of %who is to show you only what you've manually defined. |
|
2909 | purpose of %who is to show you only what you've manually defined. | |
2600 |
|
2910 | |||
|
2911 | **%who_ls**:: | |||
2601 |
|
2912 | |||
2602 |
|
|
2913 | Return a sorted list of all interactive variables. | |
2603 |
|
2914 | |||
2604 |
|
|
2915 | If arguments are given, only variables of types matching these | |
2605 | are returned. |
|
2916 | arguments are returned. | |
2606 |
|
2917 | |||
|
2918 | **%whos**:: | |||
2607 |
|
2919 | |||
2608 |
|
|
2920 | Like %who, but gives some extra information about each variable. | |
2609 |
|
2921 | |||
2610 | The same type filtering of %who can be applied here. |
|
2922 | The same type filtering of %who can be applied here. | |
2611 |
|
2923 | |||
2612 | For all variables, the type is printed. Additionally it prints: |
|
2924 | For all variables, the type is printed. Additionally it prints: | |
2613 |
|
2925 | |||
2614 |
|
|
2926 | - For {},[],(): their length. | |
2615 |
|
2927 | |||
2616 | - For numpy and Numeric arrays, a summary with shape, number of |
|
2928 | - For numpy and Numeric arrays, a summary with shape, number of | |
2617 | elements, typecode and size in memory. |
|
2929 | elements, typecode and size in memory. | |
2618 |
|
2930 | |||
2619 |
|
|
2931 | - Everything else: a string representation, snipping their middle if | |
2620 | long. |
|
2932 | too long. | |
2621 |
|
2933 | |||
|
2934 | **%xmode**:: | |||
2622 |
|
2935 | |||
2623 |
|
|
2936 | Switch modes for the exception handlers. | |
2624 |
|
2937 | |||
2625 | Valid modes: Plain, Context and Verbose. |
|
2938 | Valid modes: Plain, Context and Verbose. | |
2626 |
|
2939 | |||
2627 | If called without arguments, acts as a toggle. |
|
2940 | If called without arguments, acts as a toggle. | |
2628 |
|
2941 | |||
|
2942 | .. magic_end | |||
2629 |
|
2943 | |||
2630 | Access to the standard Python help |
|
2944 | Access to the standard Python help | |
2631 | ---------------------------------- |
|
2945 | ---------------------------------- |
General Comments 0
You need to be logged in to leave comments.
Login now