2

我在输入文件中有一条 MARC21 记录。我正在尝试以 Aleph Sequential 格式打印它。

如何?
我想打印记录号(9 位)、空格、字段标签、指标、空格、L 字母、空格,然后是每个子字段标签和子字段比赛。

我正在尝试使用 record.get_fields(),但我没有成功获取字段指示符和子字段标记。

cat 我如何获取和打印字段指示符?如何打印 ech 子字段标签,然后打印每个子字段值?

这是我的代码:

from pymarc import MARCReader
from pymarc import Record, Field 

with open('machiavellism_biu_2018.mrc', 'rb') as fh:
    reader = MARCReader(fh, to_unicode=True) 
    # loop 1
    recnum = 0
    for record in reader: 
        # loop 2
        recnum += 1
        for tield_contents in record.get_fields():
            print ('%09d' % recnum,' ',tield_contents.tag,'  ',' L',tield_contents.value())
        ## end loop 2

输出示例:

python pymarc_000002.py

...

000000001   001     L 002547390
000000001   003     L OCoLC
000000001   005     L 20181016125657.0
000000001   008     L 180214t20182018enka     b    001 0 eng
000000001   092     L 302 BER m
000000001   020     L 9781138093317
000000001   035     L (OCoLC)991673448
000000001   040     L eng rda
000000001   041     L eng
000000001   100     L Bereczkei, Tamás lat author
000000001   245     L Machiavellianism : the psychology of manipulation / Tamas Bereczkei.
000000001   264     L London : Routledge, 2018.
000000001   264     L ©2018
4

1 回答 1

0

如果 marc 字段有第一个或第二个指示符,那么它将被解析为.indicator1.indicator2属性。即使在 marc 记录中只定义了一个,它们也会被定义,所以这样的东西应该可以工作。

if hasattr(field_contents, 'indicator1'):
       indicator1 = field_contents.indicator1
       indicator2 = field_contents.indicator2
于 2019-02-11T21:07:31.903 回答