===== ipython ----- lsmagic %Exit %Pprint %Quit %alias %autocall %autoindent %automagic %bg %bookmark %cd %clear %color_info %colors %cpaste %debug %dhist %dirs %ed %edit %env %exit %hist %history %logoff %logon %logstart %logstate %lsmagic %macro %magic %p %page %pdb %pdef %pdoc %pfile %pinfo %popd %profile %prun %prun %psearch %psource %pushd %pwd %pycat %quickref %quit %r %rehash %rehashdir %rehashx %reset %run %runlog %save %sc %store %sx %system_verbose %time %timeit %unalias %upgrade %who %who_ls %whos %xmode Automagic is ON, % prefix NOT needed for magic functions. ----- who(s) ----- store Stored variables and their in-db values ----- logstart Activating auto-logging ===== ipython ---> pydoc ----- help() help> topics ASSERTION DEBUGGING LITERALS SEQUENCEMETHODS2 ASSIGNMENT DELETION LOOPING SEQUENCES ATTRIBUTEMETHODS DICTIONARIES MAPPINGMETHODS SHIFTING ATTRIBUTES DICTIONARYLITERALS MAPPINGS SLICINGS AUGMENTEDASSIGNMENT DYNAMICFEATURES METHODS SPECIALATTRIBUTES BACKQUOTES ELLIPSIS MODULES SPECIALIDENTIFIERS BASICMETHODS EXCEPTIONS NAMESPACES SPECIALMETHODS BINARY EXECUTION NONE STRINGMETHODS BITWISE EXPRESSIONS NUMBERMETHODS STRINGS BOOLEAN FILES NUMBERS SUBSCRIPTS CALLABLEMETHODS FLOAT OBJECTS TRACEBACKS CALLS FORMATTING OPERATORS TRUTHVALUE CLASSES FRAMEOBJECTS PACKAGES TUPLELITERALS CODEOBJECTS FRAMES POWER TUPLES COERCIONS FUNCTIONS PRECEDENCE TYPEOBJECTS COMPARISON IDENTIFIERS PRINTING TYPES COMPLEX IMPORTING PRIVATENAMES UNARY CONDITIONAL INTEGER RETURNING UNICODE CONTEXTMANAGERS LISTLITERALS SCOPING CONVERSIONS LISTS SEQUENCEMETHODS1 ----- help(sys) ----- help('for') ----- pdef re.match re.match(pattern, string, flags=0) ----- pdoc re.match Try to apply the pattern at the start of the string, returning a match object, or None if no match was found. ----- pinfo re.match (pdef and pdoc combined) Type: function Base Class: String Form: Namespace: Interactive File: /home/raffi/re.py Definition: re.match(pattern, string, flags=0) Docstring: Try to apply the pattern at the start of the string, returning a match object, or None if no match was found. ----- psource re.match def match(pattern, string, flags=0): """Try to apply the pattern at the start of the string, returning a match object, or None if no match was found.""" return _compile(pattern, flags).match(string) ----- re.match?? == pinfo ----- pfile ----- edit -x re.match ===== printing ----- p (print command) p sys.path ----- page page sys.path ----- def x(a, b): print a, b x 3, 4 ,x 3, 4 def y(): print "my help" /y ===== files and directories dir dirs ldir cd pushd popd bookmark spack /usr/lib/python.2.5/site-pack cd spack dhist cd -2 # use list number from dhist for cd cd? ----- ppat = "*.py" ls -l $ppat !ls -l ${ppat+'c'} alias pr echo you said: %s pr HELLO unalias pr def go(patt=patt): !ls -l $patt go() go("*so") x = !ls len(x) x.s # smart list x.l # list x.n # list with new lines x = !ls *.py | sort ===== run run calc # run python program less calc # no need for .py ----- pycat calc import os, sys class calculator(object): "Simple calculation" err_msg = "incorrect operation" def sum(self, a, b): return a + b def divide(self, a, b): return a / b if __name__ == "__main__": c = calculator() print c.divide(10, 2) ..... who <--- shows that os, sys were imported into current ipython space including var 'c' whos run can import namespace with options run -d calc # debugger ----- run -p (profiling) ===== history _i _ii _iii # previous command _i11 # i plus integer ----- hist hist -r raw hist 1 10 hist 10 # show last 10 commands exec _i3 # exec command from hist 3 exec In[1:4] ----- set var names to lines macro begin 1-4 5 begin <--- executes the macro begin? show macro print begin store begin save somename 3-5 6 # writes lines to somename.py file edit begin edit 1-20 ----- editing pycat so me.py psource somefunct cpaste ----- def m2i(mm): inchSize = 25.4 inch = mm / inchSize print '\t%.2f mm = %.2f "' % (mm, inch) return mm, inch def i2m(inSize): inch = 25.4 mm = inSize * inch print '\t%.2f " = %.2f mm\n' % (inSize, mm) edit _i123 psource m2i m2i(1100) m2i(1100); execute without returning the value(s) runlog # will rexecute commands from log file ===== output cache Out.keys() Out[115] ----- runlog ===== exceptions xmode Plain xmode Context gives lines of src code xmode Verbose lines of src code + args to call values ===== debuging debug pdb run -d program prun somefunct() (runs expressions, not files) run -p (runs files, not expressions) ----- in program ..... from ipython.Shell import IPShellEmbed ipshell = IPShellEmbed() ipshell() ===== timing time sum(range(10000)) timeit sum(range(10000)) prun i2m(1000) bg # run in background ..... ----- ----- ===== input filtering ipython -p physics m = 200 lb v = 30 mi/h e = 1.0/2.0 * m * v**2 e.convertToUnit('J') # converts internaly ipython -pylab # mathplot lab from pylab import * t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t) plot(t, s, linewidth=1.0) xlabel('time (s)') ylabel('voltage (mV)') title('simple test') grid(True) show()