← Back to team overview

pymarc-team team mailing list archive

Writing UTF-8 MARC records in pymarc

 

Hello pymarc team,

I'm working on a project where I'm taking an Excel file of Chinese
book titles and converting it to MARC records.  The goal is to upload
these to my library's ILS.

The incoming Excel file is in UTF-8 and contains all Chinese
characters. The script pulls out the relevant cells and writes out a
brief MARC record.

However, there's something wrong with the way I'm handling the MARC
leader.  MarcEdit says the leader is invalid.  My ILS won't load it.
If I recompile it into MARC from MarcEdit it loads just fine.  I'd
prefer if I could do this without having to recompile in MARC edit -
i.e. hands off.

Any input/feedback would be greatly appreciated.

code for setting leader bytes:
record = pymarc.Record()
field = pymarc.Field('245', ['1', '0'], ['a', title])
record.add_field(field)
...
l = list(record.leader)
l[5] = 'n'
l[6] = 'a'
l[7] = 'm'
l[9] = 'a'
record.leader = "".join(l)
writer.write(record)

sample output from the script:
=LDR  00355nam a2200133   4500
=001  chi38309301398
=020  \\$a9787301152621
=100  0\$a聂立泽著
=245  10$a港澳与内地刑事法律比较及刑事司法协助研究(中山大学港澳研究文丛)
=907  \\$a.b7277659

MarcEdit output for invalid leader:
Record Number: 1
Error: Leader Data invalid.
Record Text:
00306nam a2200121
4500001001500000008004000015020001800055100000900073907001400082960003700096961000800133998004300141chi38309301398//////////////cc//////////////////chi//\\a97873011526210
a聂立泽著\\a.b7277659\\o1s10.00tllibu1800vcibtczUSD\\fSAS\\anoneb
 -  -  cadmenfchigcch0i0

Thanks,
Ted



Follow ups