pymarc (and python) newbie questions

369 views
Skip to first unread message

Heidi Frank

unread,
Jul 31, 2012, 9:54:48 PM7/31/12
to pym...@googlegroups.com
Hi everyone,
I'm just starting to look into PyMarc for my work project preparing MARC records that have originated from the Archivists' Toolkit to import into our ILS (Aleph).   and I'm also new to Python in general.   I'm coming across some error messages that I'm not able to decipher but I'm assuming it's likely some amateur mistake, so just thought I'd write to see if someone here could help get me started.

right now, I'm just trying to read a .mrc file of raw MARC records, and my very basic script works to a point (i.e., I get a number of records to print), but I get these errors at the end of the screen output:
------------------------------------------------------------------------------------------
Traceback (most recent call last):
  File "./BHS2.py", line 7, in <module>
    for record in reader:
  File "/Users/heidifrank/Documents/NYU/BHS-AT2Aleph/pymarc/reader.py", line 87, in next
    utf8_handling=self.utf8_handling)
  File "/Users/heidifrank/Documents/NYU/BHS-AT2Aleph/pymarc/record.py", line 54, in __init__
    utf8_handling=utf8_handling)
  File "/Users/heidifrank/Documents/NYU/BHS-AT2Aleph/pymarc/record.py", line 158, in decode_marc
    raise RecordDirectoryInvalid
pymarc.exceptions.RecordDirectoryInvalid: Invalid directory
------------------------------------------------------------------------------------------

here's my python script:

#!/usr/bin/python
from pymarc import MARCReader
reader = MARCReader(open('00-All_MRC.mrc'))
for record in reader:
  if not record['100'] and not record['110']:
    print record


and I've attached the .mrc file that I'm reading.    when I downloaded the pymarc module, I opened the tar.gz file so that I had a folder called "pymarc-2.8.4" and inside that folder was the folder "pymarc" along with other files/folders (e.g., ez_setup.py, MANIFEST.in, PKG-INFO, etc).  I copied just the folder "pymarc" into the directory with my python script (only cause I wasn't sure how to point to the folder within the parent folder), so i'm wondering if that's the problem...  are the other files in the parent folder needed for the module to work?

Can anyone tell offhand if these errors have to do with the location of my pymarc module, or if it has something to do with the .mrc file I'm reading, or something else...?
any ideas much appreciated!
heidi
00-All_MRC.mrc

Mark A. Matienzo

unread,
Jul 31, 2012, 10:59:14 PM7/31/12
to pym...@googlegroups.com
Hello Heidi -

On Tue, Jul 31, 2012 at 9:54 PM, Heidi Frank <hf...@nyu.edu> wrote:
> I get these errors at the end of the screen output:
> ------------------------------------------------------------------------------------------
> Traceback (most recent call last):
> File "./BHS2.py", line 7, in <module>
> for record in reader:
> File "/Users/heidifrank/Documents/NYU/BHS-AT2Aleph/pymarc/reader.py", line
> 87, in next
> utf8_handling=self.utf8_handling)
> File "/Users/heidifrank/Documents/NYU/BHS-AT2Aleph/pymarc/record.py", line
> 54, in __init__
> utf8_handling=utf8_handling)
> File "/Users/heidifrank/Documents/NYU/BHS-AT2Aleph/pymarc/record.py", line
> 158, in decode_marc
> raise RecordDirectoryInvalid
> pymarc.exceptions.RecordDirectoryInvalid: Invalid directory
> ------------------------------------------------------------------------------------------
>
> [..snip..]
>
> Can anyone tell offhand if these errors have to do with the location of my
> pymarc module, or if it has something to do with the .mrc file I'm reading,
> or something else...?

It has to do with the MARC file that you're reading - it's definitely
not an issue with the module. This error is stating that the directory
of the MARC record is invalid.

It appears that two records have invalid directories in this file and
couldn't be parsed by pymarc. I've written them out to a file, which
is attached. (The method by which to do this using Python is left as
an exercise to the reader, but I'm happy to share if you'd find it
useful.)

Let me know if this was helpful.

Cheers,
Mark

Mark A. Matienzo <ma...@matienzo.org>
Digital Archivist, Manuscripts and Archives, Yale University Library
Technical Architect, ArchivesSpace
bad.mrc

Heidi Frank

unread,
Aug 1, 2012, 7:40:15 PM8/1/12
to pym...@googlegroups.com, ma...@matienzo.org
Hi Mark!
Aaah, yes indeed, these 2 records were ones I had identified in MarcEdit from the validation errors that didn't convert correctly (I think something to do with particular chars used in the long note fields, but haven't investigated that yet) - I didn't realize those records would cause the errors with pymarc so have deleted them from the file and will try my luck again tonight...

thanks for taking the time to figure this out!   ...hopefully this will get me moving again.
best,
heidi
Reply all
Reply to author
Forward
0 new messages