File: commasep.py

package info (click to toggle)
pyparsing 2.1.10%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,412 kB
  • ctags: 8,284
  • sloc: python: 11,929; sh: 17; makefile: 7
file content (26 lines) | stat: -rw-r--r-- 791 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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
#
# Copyright (c) 2004-2016, Paul McGuire
#

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()