summaryrefslogtreecommitdiff
path: root/src/examples/commasep.py
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2012-10-02 04:55:56 +0000
committerPaul McGuire <ptmcg@austin.rr.com>2012-10-02 04:55:56 +0000
commita7f9dda0668bfce4fba51df1bf2976b4a93a8bd5 (patch)
tree57ea8bcf2e66532a36c833a7bc57cff9d5d0e4dd /src/examples/commasep.py
parentf5d2b716ffb57b65660a7ee0bbf04332dfb29620 (diff)
downloadpyparsing-git-a7f9dda0668bfce4fba51df1bf2976b4a93a8bd5.tar.gz
Add example files to SVN
Diffstat (limited to 'src/examples/commasep.py')
-rw-r--r--src/examples/commasep.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/examples/commasep.py b/src/examples/commasep.py
new file mode 100644
index 0000000..d753eca
--- /dev/null
+++ b/src/examples/commasep.py
@@ -0,0 +1,23 @@
+# commasep.py
+#
+# comma-separated list example, to illustrate the advantages of using
+# the pyparsing commaSeparatedList as opposed to string.split(","):
+# - leading and trailing whitespace is implicitly trimmed from list elements
+# - list elements can be quoted strings, which can safely contain commas without breaking
+# into separate elements
+
+from pyparsing import commaSeparatedList
+
+testData = [
+ "a,b,c,100.2,,3",
+ "d, e, j k , m ",
+ "'Hello, World', f, g , , 5.1,x",
+ "John Doe, 123 Main St., Cleveland, Ohio",
+ "Jane Doe, 456 St. James St., Los Angeles , California ",
+ "",
+ ]
+
+for line in testData:
+ print commaSeparatedList.parseString(line)
+ print line.split(",")
+ print