From 1d9341fd0783421f1615683b6fd7f808b7907301 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Thu, 11 Aug 2016 21:04:33 +0000 Subject: Clearer example output in ParseResults git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@414 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b --- src/pyparsing.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/pyparsing.py b/src/pyparsing.py index 03a7371..e101ab4 100644 --- a/src/pyparsing.py +++ b/src/pyparsing.py @@ -309,23 +309,26 @@ class ParseResults(object): + integer.setResultsName("day")) # equivalent form: # date_str = integer("year") + '/' + integer("month") + '/' + integer("day") - + result = date_str.parseString("1999/12/31") - print(list(result)) - print(result[0]) - print(result['month']) - print(result.day) - print('month' in result) - print('minutes' in result) - print(result.dump()) + + def test(s, fn=repr): + print("%s -> %s" % (s, fn(eval(s)))) + test("list(result)") + test("result[0]") + test("result['month']") + test("result.day") + test("'month' in result") + test("'minutes' in result") + test("result.dump()", str) prints:: - ['1999', '/', '12', '/', '31'] - 1999 - 12 - 31 - True - False - ['1999', '/', '12', '/', '31'] + list(result) -> ['1999', '/', '12', '/', '31'] + result[0] -> '1999' + result['month'] -> '12' + result.day -> '31' + 'month' in result -> True + 'minutes' in result -> False + result.dump() -> ['1999', '/', '12', '/', '31'] - day: 31 - month: 12 - year: 1999 -- cgit v1.2.1