Herramientas de usuario

Herramientas del sitio


pymarc

Tabla de Contenidos

pymarc

Atención: existe otro proyecto similar, PyMARC en SourceForge, by mstetson. Incluye MarcBreaker.py y MarcMaker.py.

pymarc 2.0 / read, write and modify MARC bibliographic data

Web: http://pypi.python.org/pypi/pymarc/2.0

Code: http://fruct.us/bzr/pymarc/

PACKAGE CONTENTS

  • constants
  • exceptions
  • field
  • marc8
  • marc8_mapping
  • marcxml
  • reader
  • record
  • writer

record

class Record(object):
  A class for representing a MARC record. Each Record object is made up of
  multiple Field objects. You'll probably want to look at the docs for Field
  to see how to fully use a Record object.
  
  Basic usage:
  
      field = Field(
          tag = '245', 
          indicators = ['0','1'],
          subfields = [
              'a', 'The pragmatic programmer : ',
              'b', 'from journeyman to master /', 
              'c', 'Andrew Hunt, David Thomas.',
          ])
  
      record.add_field(field)
  
  Or creating a record from a chunk of MARC in transmission format:
  
      record = Record(data=chunk)
  
  Or getting a record as serialized MARC21.
  
      raw = record.as_marc21()
  
  You'll normally want to use a MARCReader object to iterate through 
  MARC records in a file.  

Methods

  def __init__(self, data=''):
    Si len(data) > 0 llama a self.decode_marc(data)
  def __str__(self):
      In a string context a Record object will return a prettified version
      of the record in MARCMaker format. See the docstring for Field.__str__
      for more information.
  def __getitem__(self, tag):
      Allows a shorthand lookup by tag:
      
          record['245']
  def __iter__(self):
     Usado para iterar sobre los campos; ver next()
  def next(self):
     Usado para iterar sobre los campos
  def add_field(self, *fields):
      add_field() will add pymarc.Field objects to a Record object.
      Optionally you can pass in multiple fields.
  def get_fields(self, *args):
      When passed a tag ('245'), get_fields() will return a list of all the 
      fields in a record with a given tag. 
      
          title = record.get_fields('245')
      
      If no fields with the specified 
      tag are found then an empty list is returned. If you are interested
      in more than one tag you can pass in a list:
      
          subjects = record.get_fields('600', '610', '650') 
      
      If no tag is passed in to fields() a list of all the fields will be 
      returned.
  def decode_marc(self, marc):
      decode_marc() accepts a MARC record in transmission format as a
      a string argument, and will populate the object based on the data
      found. The Record constructor actually uses decode_marc() behind
      the scenes when you pass in a chunk of MARC data to it.
  def as_marc21(self):
      returns the record serialized as MARC21

Estos métodos devuelven campos específicos:

  def title(self):
  def isbn(self):
  def author(self):
  ...

field

class Field(object):
  Field() pass in the field tag, indicators and subfields for the tag.
  
      field = Field(
          tag = '245',
          indicators = ['0','1'],
          subfields = [                               NOTE: positions 0, 2, 4, ... are codes; 1, 3, 5, ... are values
              'a', 'The pragmatic programmer : ',
              'b', 'from journeyman to master /', 
              'c', 'Andrew Hunt, David Thomas.',
          ]
  
  If you want to create a control field, don't pass in the indicators
  and use a data parameter rather than a subfields parameter:
  
      field = Field(tag='001', data='fol05731351')

Methods

  def __init__(self, tag, indicators=None, subfields=None, data=''):
    data se usa sólo para campos de control (tag < 010)
  def __iter__(self):
    usado para iterar sobre los subcampos (ver next())
    Devuelve: self
  def __str__(self):
      A Field object in a string context will return the tag, indicators
      and subfield as a string. This follows MARCMaker format; see [1]
      and [2] for further reference. Special character mnemonic strings
      have yet to be implemented (see [3]), so be forewarned. Note also
      for complete MARCMaker compatibility, you will need to change your
      newlines to DOS format ('\r\n').
      
      [1] http://www.loc.gov/marc/makrbrkr.html#mechanics
      [2] http://search.cpan.org/~eijabb/MARC-File-MARCMaker/
      [3] http://www.loc.gov/marc/mnemonics.html
      
      Devuelve: string
  def __getitem__(self, subfield):
      Retrieve the first subfield with a given subfield code in a field:
      
          field['a']
      
      Handy for quick lookups.
  def next(self):
    usado para iterar sobre los subcampos
  def value(self):
      Returns the field as a string without tag, indicators, and 
      subfield indicators.
  def get_subfields(self, *codes):
      get_subfields() accepts one or more subfield codes and returns
      a list of subfield values.  The order of the subfield values
      in the list will be the order that they appear in the field.
      
          print field.get_subfields('a')
          print field.get_subfields('a', 'b', 'z')
      
      Devuelve: None o lista de valores, e.g. ['Pérez, Juan,', '1954-']
  def add_subfield(self, code, value):
      Adds a subfield code/value pair to the field.
      
          field.add_subfield('u', 'http://www.loc.gov')
      
      Devuelve: nada
  def is_control_field(self):
      returns true or false if the field is considered a control field.
      Control fields lack indicators and subfields.
      
      Devuelve: boolean
  def as_marc21(self):
      used during conversion of a field to raw marc
      
      Devuelve: string
  def format_field(self):
      Returns the field as a string without tag, indicators, and
      subfield indicators. Like pymarc.Field.value(), but prettier
      (adds spaces, formats subject headings).
      
      Devuelve: string
  def is_subject_field(self):
      Returns True or False if the field is considered a subject
      field.  Used by format_field.
      
      Devuelve: boolean
pymarc.txt · Última modificación: 2009/08/19 00:00 (editor externo)