summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-08-11 21:04:33 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-08-11 21:04:33 +0000
commit1d9341fd0783421f1615683b6fd7f808b7907301 (patch)
tree1a46ef519d1e9d1c5970c7ebf3976970dbef0049
parent1dc0a6a8706e0c542085429702affa421d5a8938 (diff)
downloadpyparsing-1d9341fd0783421f1615683b6fd7f808b7907301.tar.gz
Clearer example output in ParseResults
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@414 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/pyparsing.py33
1 files 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