Jonathan Eunice avatar Jonathan Eunice committed 4976e51

ready to publish

Comments (0)

Files changed (4)

 will turn on location reporting. This can also be set on call-by-call basis.
 ``show`` is built atop the `options <http://pypi.python.org/pypi/options>`_ module
 for configuration management, and also the output management of
-`say <http://pypi.python.org/pypi/say>`_. All ``say`` options work in show.
-See that module for additional detail.
+`say <http://pypi.python.org/pypi/say>`_. All ``say`` options work in show. If you
+``show()`` a literal string, it will be iterpolated as it would be in ``say``::
+
+    show("{n} iterations, still running")
+    
+yields something like::
+
+    14312 iterations, still running
+    
+While::
+
+    s = '{n} iterations'
+    show(s)
+    
+yields::
+
+    s: '{n} iterations'
+    
+See ``say`` `say <http://pypi.python.org/pypi/say>`_ for additional detail on its
+operation.
 
 Showing Collections
 ===================
 
+The goal of ``show`` is to provide the most useful information possible,
+in the quickest and simplest way. Not requiring programmers to explicitly
+restate values and names in print statements is the start, but the module also
+provides some additional functions that provide a bit more semantic value.
+For example, ``say.items()`` is designed to make printing collections easy.
+It shows not just the values, but also the cardinality (i.e., length) of the
+collection::
+
+    nums = list(range(4))
+    show.items(nums)
+    
+yields::
+
+    nums (4 items): [0, 1, 2, 3]
+
 Showing Object Properties
 =========================
 
 an object, and isn't used in the technical sense of Python properties.)
 Properties will be listed alphabetically, but with those starting with underscores
 (``_``), usually indicating "private" data, sorted after those that are
-conventionally considered public.
+conventionally considered public. 
 
 If ``x`` has real ``@property`` members, those too displayed. However, other class
 attributes that ``x`` rightfully inherits, but that are not directly present in the
 
 Notes
 =====
-   
+
+ *  ``show`` is in its early days. Over time, it will provide additional
+    context-specific output helpers. For example, the "diff" views of ``py.test``
+    seem a high-value enhancement.
+ 
  *  Automated multi-version testing managed with the wonderful
     `pytest <http://pypi.python.org/pypi/pytest>`_
     and `tox <http://pypi.python.org/pypi/tox>`_. ``show`` is 
 
 setup(
     name='show',
-    version=verno("0.430"),
+    version=verno("0.437"),
     author='Jonathan Eunice',
     author_email='jonathan.eunice@gmail.com',
     description='Debug print statements, done right. E.g. show(x)',
 # probably cannot make this work from interactive Python
 # http://stackoverflow.com/questions/13204161/how-to-access-the-calling-source-line-from-interactive-shell
 
+def format_escape(s):
+    """
+    Double { and } characters in a string to 'escape' them so ``str.format``
+    doesn't treat them as template characters. NB This is NOT idempotent!
+    Escaping more than once (when { or } are present ) = ERROR.
+    """
+    return s.replace('{', '{{').replace('}', '}}') 
+    
 class Show(object):
     """Show objects print debug output in a 'name: value' format that
     is convenient for discovering what's going on as a program runs."""
         is eventually output by ``say``.
         """
         fvalue = repr(value)
-        if isinstance(value, (dict, set)):
-            fvalue = fvalue.replace('{', '{{').replace('}', '}}') # escape { and }
-        return fvalue
+        return format_escape(fvalue)
 
     def arg_format(self, name, value, caller):
         """

test/test_show.py

     x = 44
     assert show("x = {x}") == 'x = 44'
     
+def test_string_example():
+    
+    n = 14312
+    assert show("{n} iterations, still running") == "14312 iterations, still running"
+
+    s = '{n} iterations'
+    assert show(s) == "s: '{n} iterations'"
+        
 def test_set():
     
     s = set([1,2,99])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.