Show More
@@ -1329,7 +1329,7 b' Currently the magic system has the following functions:\\n"""' | |||
|
1329 | 1329 | contains profiler specific options as described here. |
|
1330 | 1330 | |
|
1331 | 1331 | You can read the complete documentation for the profile module with:\\ |
|
1332 |
In [ |
|
|
1332 | In []: import profile; profile.help() """ | |
|
1333 | 1333 | |
|
1334 | 1334 | opts_def = Struct(D=[''],l=[],s=['time'],T=['']) |
|
1335 | 1335 | # protect user quote marks |
@@ -1755,7 +1755,7 b' Currently the magic system has the following functions:\\n"""' | |||
|
1755 | 1755 | import timeit |
|
1756 | 1756 | import math |
|
1757 | 1757 | |
|
1758 |
units = ["s", "ms", " |
|
|
1758 | units = [u"s", u"ms", u"\xb5s", u"ns"] | |
|
1759 | 1759 | scaling = [1, 1e3, 1e6, 1e9] |
|
1760 | 1760 | |
|
1761 | 1761 | opts, stmt = self.parse_options(parameter_s,'n:r:tcp:', |
@@ -1804,7 +1804,7 b' Currently the magic system has the following functions:\\n"""' | |||
|
1804 | 1804 | order = min(-int(math.floor(math.log10(best)) // 3), 3) |
|
1805 | 1805 | else: |
|
1806 | 1806 | order = 3 |
|
1807 | print "%d loops, best of %d: %.*g %s per loop" % (number, repeat, | |
|
1807 | print u"%d loops, best of %d: %.*g %s per loop" % (number, repeat, | |
|
1808 | 1808 | precision, |
|
1809 | 1809 | best * scaling[order], |
|
1810 | 1810 | units[order]) |
@@ -1941,7 +1941,7 b' Currently the magic system has the following functions:\\n"""' | |||
|
1941 | 1941 | you can create a macro with lines 44 through 47 (included) and line 49 |
|
1942 | 1942 | called my_macro with: |
|
1943 | 1943 | |
|
1944 |
In [ |
|
|
1944 | In []: %macro my_macro 44-47 49 | |
|
1945 | 1945 | |
|
1946 | 1946 | Now, typing `my_macro` (without quotes) will re-execute all this code |
|
1947 | 1947 | in one pass. |
@@ -1962,7 +1962,7 b' Currently the magic system has the following functions:\\n"""' | |||
|
1962 | 1962 | can obtain similar results by explicitly executing slices from your |
|
1963 | 1963 | input history with: |
|
1964 | 1964 | |
|
1965 |
In [ |
|
|
1965 | In []: exec In[44:48]+In[49]""" | |
|
1966 | 1966 | |
|
1967 | 1967 | opts,args = self.parse_options(parameter_s,'r',mode='list') |
|
1968 | 1968 | if not args: |
@@ -2126,47 +2126,47 b' Currently the magic system has the following functions:\\n"""' | |||
|
2126 | 2126 | This is an example of creating a simple function inside the editor and |
|
2127 | 2127 | then modifying it. First, start up the editor: |
|
2128 | 2128 | |
|
2129 |
In [ |
|
|
2129 | In []: ed\\ | |
|
2130 | 2130 | Editing... done. Executing edited code...\\ |
|
2131 |
Out[ |
|
|
2131 | Out[]: 'def foo():\\n print "foo() was defined in an editing session"\\n' | |
|
2132 | 2132 | |
|
2133 | 2133 | We can then call the function foo(): |
|
2134 | 2134 | |
|
2135 |
In [ |
|
|
2135 | In []: foo()\\ | |
|
2136 | 2136 | foo() was defined in an editing session |
|
2137 | 2137 | |
|
2138 | 2138 | Now we edit foo. IPython automatically loads the editor with the |
|
2139 | 2139 | (temporary) file where foo() was previously defined: |
|
2140 | 2140 | |
|
2141 |
In [ |
|
|
2141 | In []: ed foo\\ | |
|
2142 | 2142 | Editing... done. Executing edited code... |
|
2143 | 2143 | |
|
2144 | 2144 | And if we call foo() again we get the modified version: |
|
2145 | 2145 | |
|
2146 |
In [ |
|
|
2146 | In []: foo()\\ | |
|
2147 | 2147 | foo() has now been changed! |
|
2148 | 2148 | |
|
2149 | 2149 | Here is an example of how to edit a code snippet successive |
|
2150 | 2150 | times. First we call the editor: |
|
2151 | 2151 | |
|
2152 |
In [ |
|
|
2152 | In []: ed\\ | |
|
2153 | 2153 | Editing... done. Executing edited code...\\ |
|
2154 | 2154 | hello\\ |
|
2155 |
Out[ |
|
|
2155 | Out[]: "print 'hello'\\n" | |
|
2156 | 2156 | |
|
2157 | 2157 | Now we call it again with the previous output (stored in _): |
|
2158 | 2158 | |
|
2159 |
In [ |
|
|
2159 | In []: ed _\\ | |
|
2160 | 2160 | Editing... done. Executing edited code...\\ |
|
2161 | 2161 | hello world\\ |
|
2162 |
Out[ |
|
|
2162 | Out[]: "print 'hello world'\\n" | |
|
2163 | 2163 | |
|
2164 | 2164 | Now we call it with the output #8 (stored in _8, also as Out[8]): |
|
2165 | 2165 | |
|
2166 |
In [ |
|
|
2166 | In []: ed _8\\ | |
|
2167 | 2167 | Editing... done. Executing edited code...\\ |
|
2168 | 2168 | hello again\\ |
|
2169 |
Out[ |
|
|
2169 | Out[]: "print 'hello again'\\n" | |
|
2170 | 2170 | |
|
2171 | 2171 | |
|
2172 | 2172 | Changing the default editor hook: |
@@ -2867,30 +2867,30 b' Defaulting color scheme to \'NoColor\'"""' | |||
|
2867 | 2867 | For example: |
|
2868 | 2868 | |
|
2869 | 2869 | # Capture into variable a |
|
2870 |
In [ |
|
|
2870 | In []: sc a=ls *py | |
|
2871 | 2871 | |
|
2872 | 2872 | # a is a string with embedded newlines |
|
2873 |
In [ |
|
|
2874 |
Out[ |
|
|
2873 | In []: a | |
|
2874 | Out[]: 'setup.py\nwin32_manual_post_install.py' | |
|
2875 | 2875 | |
|
2876 | 2876 | # which can be seen as a list: |
|
2877 |
In [ |
|
|
2878 |
Out[ |
|
|
2877 | In []: a.l | |
|
2878 | Out[]: ['setup.py', 'win32_manual_post_install.py'] | |
|
2879 | 2879 | |
|
2880 | 2880 | # or as a whitespace-separated string: |
|
2881 |
In [ |
|
|
2882 |
Out[ |
|
|
2881 | In []: a.s | |
|
2882 | Out[]: 'setup.py win32_manual_post_install.py' | |
|
2883 | 2883 | |
|
2884 | 2884 | # a.s is useful to pass as a single command line: |
|
2885 |
In [ |
|
|
2885 | In []: !wc -l $a.s | |
|
2886 | 2886 | 146 setup.py |
|
2887 | 2887 | 130 win32_manual_post_install.py |
|
2888 | 2888 | 276 total |
|
2889 | 2889 | |
|
2890 | 2890 | # while the list form is useful to loop over: |
|
2891 |
In [ |
|
|
2892 |
|
|
|
2893 |
|
|
|
2891 | In []: for f in a.l: | |
|
2892 | ...: !wc -l $f | |
|
2893 | ...: | |
|
2894 | 2894 | 146 setup.py |
|
2895 | 2895 | 130 win32_manual_post_install.py |
|
2896 | 2896 | |
@@ -2898,13 +2898,13 b' Defaulting color scheme to \'NoColor\'"""' | |||
|
2898 | 2898 | the sense that you can equally invoke the .s attribute on them to |
|
2899 | 2899 | automatically get a whitespace-separated string from their contents: |
|
2900 | 2900 | |
|
2901 |
In [ |
|
|
2901 | In []: sc -l b=ls *py | |
|
2902 | 2902 | |
|
2903 |
In [ |
|
|
2904 |
Out[ |
|
|
2903 | In []: b | |
|
2904 | Out[]: ['setup.py', 'win32_manual_post_install.py'] | |
|
2905 | 2905 | |
|
2906 |
In [ |
|
|
2907 |
Out[ |
|
|
2906 | In []: b.s | |
|
2907 | Out[]: 'setup.py win32_manual_post_install.py' | |
|
2908 | 2908 | |
|
2909 | 2909 | In summary, both the lists and strings used for ouptut capture have |
|
2910 | 2910 | the following special attributes: |
General Comments 0
You need to be logged in to leave comments.
Login now