public
Created

Basic pymarc usage example.

  • Download Gist
simpledump.py
Python
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 27 28 29
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
"""
Example usage: python simpledump.py data/marc/010-lok.mrc
 
"""
 
import pymarc
import sys
 
def dump(filename):
reader = pymarc.MARCReader(file(filename))
for record in reader:
print 'Leader ==>', record.leader
for field in record:
print field.tag, '|',
if hasattr(field, 'subfields'):
print 'Indicators ==>', field.indicators,
print 'Subfields ==>', field.subfields
else:
print field.data
print '-' * 48
 
if __name__ == '__main__':
try:
dump(sys.argv[1])
except IndexError:
print 'usage: %s FILENAME' % sys.argv[0]

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.