export LESS="-R" export EDITOR=emacsThis will tell the pager program less to interpret "raw" control sequences appropriately, and to use emacs as your default editor in certain situations. IPython uses raw control sequences to make colored text in its displays.
The following ipython commands may be of use to you.
g = MakeSmallWorldNetwork(100, 4, 0.1) g.TAB # i.e., hit the TAB key after typing "g."then you will be presented with the possible completions of the command g. :
g.AddEdge g.GetNeighbors g.HasNode g.__doc__ g.__module__ g.AddNode g.GetNodes g.__class__ g.__init__ g.neighbor_dict
Type: instancemethod Base Class: <type 'instancemethod'> String Form: <bound method UndirectedGraph.AddEdge of <Networks.UndirectedGraph instance at 0x369ea30>> Namespace: Interactive File: /Users/myers/teaching/ComputationalMethods/ComputerExercises/PythonSoftware/Networks.py Definition: g.AddEdge(self, node1, node2) Docstring: Add node1 and node2 to network first Adds new edge (appends node2 to neighbor_dict[node1] and vice-versa, since it's an undirected graph) Do so only if old edge does not already exist (node2 not in neighbor_dict[node1])Typing two question marks lists the not only the summary information produced above, but also shows the source code used to define the object of interest.
Variable Type Data/Info ------------------------------------------------------------------------ AddRandomEdges function <function AddRandomEdges at 0x34a8230> FindAverageAveragePathLength function <function FindAverageAver<...>ePathLength at 0x34a8130> FindAverageClusteringCoefficient function <function FindAverageClus<...>Coefficient at 0x34a8030> GetClustering_vs_p function <function GetClustering_vs_p at 0x34a8570> GetPathLength_vs_p function <function GetPathLength_vs_p at 0x34a80f0> MakePathLengthHistograms function <function MakePathLengthHistograms at 0x34a8170> MakeRingGraph function <function MakeRingGraph at 0x34a8270> MakeSmallWorldNetwork function <function MakeSmallWorldNetwork at 0x34a81f0> MultiPlot module <module 'MultiPlot' from <...>nSoftware/MultiPlot.pyc'> NetGraphics module <module 'NetGraphics' fro<...>oftware/NetGraphics.pyc'> Networks module <module 'Networks' from 'Networks.pyc'> Percolation module <module 'Percolation' from 'Percolation.py'> PlotClustering_vs_p function <function PlotClustering_vs_p at 0x34a8730> PlotPathLength_vs_p function <function PlotPathLength_vs_p at 0x34a80b0> PlotScaledPathLength_vs_pZL function <function PlotScaledPathL<...>ngth_vs_pZL at 0x34a8070> PlotWattsStrogatzFig2 function <function PlotWattsStrogatzFig2 at 0x34a8770> SmallWorldBetweenness function <function SmallWorldBetweenness at 0x34a87f0> SmallWorldSimple function <function SmallWorldSimple at 0x34a81b0> TestBetweennessSimple function <function TestBetweennessSimple at 0x34a87b0> g Networks.UndirectedGraph <Networks.UndirectedGraph instance at 0x369ea30> numpy module <module 'numpy' from '/sw<...>ages/numpy/__init__.pyc'> os module <module 'os' from '/sw/lib/python2.5/os.pyc'> pylab module <module 'pylab' from '/sw<...>site-packages/pylab.pyc'> random module <module 'random' from '/s<...>ib/python2.5/random.pyc'>Output from %whos can be restricted to objects of a specified type; e.g., typing %whos function will print out only those objects in the namespace that are functions.
%run SmallWorldNetworks g = MakeSmallWorldNetwork(100, 4, 0.1) NetGraphics.DisplayCircleGraph(g) distances = Networks.FindPathLengthsFromNode(g, 0) print distancesthen I can make a macro called runswn (short for RunSmallWorldNetworks) that executes everything from lines 1 through 5, inclusive:
%macro runswn 1-5It is obviously of use to run %hist to find which specific line numbers need to be included in the macro. Line numbers need not be contiguous, e.g., %macro runswn 1-5 7 12-15 will assemble a macro from the specified disjoint set of command lines.
%edit SmallWorldNetworks.py # opens the file SmallWorldNetworks.py %edit MakeSmallWorldNetwork # opens the source file containing the function MakeSmallWorldNetwork %edit runswn # opens the runswn macro defined above in a temporary file %edit 1-5 7 12-15 # opens a temporary file containing the input lines 1-5, 7, and 12-15
import pdb pdb.run('Networks.FindPathLengthsFromNode(g, 0)')This puts you into the debugger, from which you can do the usual sort of things (list source code, set breakpoints, step one line at a time, continue until a breakpoint or exception is reached, etc.). Type ? at the pdb prompt for a list of available commands. As noted above, setting %pdb on within ipython will make it such that the pdb debugger will automatically be started at the point of an exception, once it is encountered.
Similarly, the python profile module is useful for identifying
how much time is spent in various functions. The syntax is similar to that
for debugging:
import profile
profile.run('Networks.FindPathLengthsFromNode(g, 0)')