Paste number 44689: edsu: marc8 to utf8 sample for pymarc

Paste number 44689: edsu: marc8 to utf8 sample for pymarc
Pasted by: anarchivist
1 year, 5 months ago
#code4lib
Paste contents:
Raw Source | XML | Display As
from pymarc import *
import sys

def marc8_to_utf( marc8string ):
  converter = MARC8_to_Unicode()
  converted = converter.translate(marc8string)
  converted = unicodedata.normalize('NFC', converted)
  return converted

reader = MARCReader(file(sys.argv[1]))
titlefile = open(sys.argv[2], 'w')
for record in reader:
  marc8title = record['245'].value()
  utf8title = marc8_to_utf(marc8title)
  titlefile.write(utf8title.encode("utf8"))
  titlefile.write('\n')
titlefile.close()

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.