##// END OF EJS Templates
Use str.format in core magics.
Thomas Kluyver -
Show More
@@ -51,7 +51,6 b' from IPython.core.macro import Macro'
51 from IPython.core import page
51 from IPython.core import page
52 from IPython.core.prefilter import ESC_MAGIC
52 from IPython.core.prefilter import ESC_MAGIC
53 from IPython.lib.pylabtools import mpl_runner
53 from IPython.lib.pylabtools import mpl_runner
54 from IPython.external.Itpl import itpl, printpl
55 from IPython.testing.skipdoctest import skip_doctest
54 from IPython.testing.skipdoctest import skip_doctest
56 from IPython.utils.io import file_read, nlprint
55 from IPython.utils.io import file_read, nlprint
57 from IPython.utils.path import get_py_filename
56 from IPython.utils.path import get_py_filename
@@ -915,8 +914,7 b' Currently the magic system has the following functions:\\n"""'
915 datalabel = 'Data/Info'
914 datalabel = 'Data/Info'
916 colsep = 3
915 colsep = 3
917 # variable format strings
916 # variable format strings
918 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
917 vformat = "{0:<{varwidth}}{1:<{typewidth}}"
919 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
920 aformat = "%s: %s elems, type `%s`, %s bytes"
918 aformat = "%s: %s elems, type `%s`, %s bytes"
921 # find the size of the columns to format the output nicely
919 # find the size of the columns to format the output nicely
922 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
920 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
@@ -928,7 +926,7 b' Currently the magic system has the following functions:\\n"""'
928 kb = 1024
926 kb = 1024
929 Mb = 1048576 # kb**2
927 Mb = 1048576 # kb**2
930 for vname,var,vtype in zip(varnames,varlist,typelist):
928 for vname,var,vtype in zip(varnames,varlist,typelist):
931 print itpl(vformat),
929 print vformat.format(vname, vtype, varwidth=varwidth, typewidth=typewidth),
932 if vtype in seq_types:
930 if vtype in seq_types:
933 print "n="+str(len(var))
931 print "n="+str(len(var))
934 elif vtype in [array_type,ndarray_type]:
932 elif vtype in [array_type,ndarray_type]:
@@ -962,7 +960,7 b' Currently the magic system has the following functions:\\n"""'
962 if len(vstr) < 50:
960 if len(vstr) < 50:
963 print vstr
961 print vstr
964 else:
962 else:
965 printpl(vfmt_short)
963 print vstr[:25] + "<...>" + vstr[-25:]
966
964
967 def magic_reset(self, parameter_s=''):
965 def magic_reset(self, parameter_s=''):
968 """Resets the namespace by removing all names defined by the user.
966 """Resets the namespace by removing all names defined by the user.
General Comments 0
You need to be logged in to leave comments. Login now