commasep.py 710 B

123456789101112131415161718192021222324
  1. # commasep.py
  2. #
  3. # comma-separated list example, to illustrate the advantages of using
  4. # the pyparsing comma_separated_list as opposed to string.split(","):
  5. # - leading and trailing whitespace is implicitly trimmed from list elements
  6. # - list elements can be quoted strings, which can safely contain commas without breaking
  7. # into separate elements
  8. #
  9. # Copyright (c) 2004-2016, Paul McGuire
  10. #
  11. import pyparsing as pp
  12. ppc = pp.pyparsing_common
  13. testData = [
  14. "a,b,c,100.2,,3",
  15. "d, e, j k , m ",
  16. "'Hello, World', f, g , , 5.1,x",
  17. "John Doe, 123 Main St., Cleveland, Ohio",
  18. "Jane Doe, 456 St. James St., Los Angeles , California ",
  19. "",
  20. ]
  21. ppc.comma_separated_list.runTests(testData)