Permalink
Browse files

Space out definitions in physics extension.

  • Loading branch information...
1 parent 9b3d679 commit 557c513e3068af1def1aecc47330df8d82956832 @takluyver committed Oct 31, 2011
Showing with 6 additions and 0 deletions.
  1. +6 −0 IPython/extensions/physics.py
@@ -83,6 +83,7 @@
def replace_inline(match):
return 'Q(\'' + match.group(1).replace('^', '**') + '\')'
+
def replace_slash(match):
expr = match.group(1)
unit = str(match.group(2)) # PhysicalQuantity doesn't like Unicode strings
@@ -91,12 +92,15 @@ def replace_slash(match):
elif not expr:
expr = '_'
return '(' + expr + ').inUnitsOf(%r)' % unit
+
def replace_conv(match):
return 'Q(\'' + match.group(1).replace('^', '**') + '\').inUnitsOf(%r)' % \
str(match.group(4))
+
def replace_assign(match):
return '%s = Q(\'%s\')' % (match.group(1), match.group(2).replace('^', '**'))
+
class QTransformer(object):
# XXX: inheriting from PrefilterTransformer as documented gives TypeErrors,
# but apparently is not needed after all
@@ -113,6 +117,7 @@ def Q(v):
try: return PhysicalQuantity(v)
except NameError: raise ValueError('invalid unit in %r' % v)
+
def tbl_magic(shell, arg):
"""tbl <expr>: Evaluate <expr> for a range of parameters, given
as "?name" in the expr.
@@ -142,6 +147,7 @@ def tbl_magic(shell, arg):
expr = '(' + expr + ').inUnitsOf("' + unit + '")'
shell.run_cell(expr, False)
+
# monkey-patch a little
global_precision = [8]
PhysicalQuantity.__str__ = \

0 comments on commit 557c513

Please sign in to comment.