Skip to content

Commit

Permalink
Update the README to describe TextStyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
danizen committed Mar 12, 2021
1 parent 54e21d5 commit 630d8b2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,34 @@ parser = MarcSearchParser()
spec = parser.parse('650$a$0')
with open(sys.argv[1], 'rb') as f:
for record in MARCReader(f):
subjects = spec.search(record, field_delimiter=':', subfield_delimiter=',')
subjects = spec.search(record)
print(subjects)
```

The `TextStyle` class governs how results are combined into strings (or not).
You can subclass `TextStyle` or `BaseTextStyle` to do anything you want with combining
the results, or you can handle it yourself.

There is also a `MarcSearch` object that memoizes each search expression, so that
you can conveniently run a number of different searches without creating several
parsed specs. For example:

```python
import csv
import sys
from pymarcspec import MarcSearch
from pymarcspec import MarcSearch, TextStyle
from pymarc import MARCReader

writer = csv.writer(sys.stdout, dialect='unix', quoting=csv.QUOTE_MINIMAL)
writer.writerow(['id', 'title', 'subjects'])

marcsearch = MarcSearch()
style = TextStyle(field_delimiter=':')
marcsearch = MarcSearch(style)
with open(sys.argv[1], 'rb') as f:
for record in MARCReader(f):
control_id = marcsearch.search('100', record)
title = marcsearch.search('245[0]$a-c', record)
subjects = marcsearch.search('650$a', record, field_delimiter=', ')
subjects = marcsearch.search('650$a', record)
writer.writerow([control_id, title, subjects])
```

Expand Down

0 comments on commit 630d8b2

Please sign in to comment.