读、写、改marc书目数据

pymarc的Python项目详细描述


 _ __  _   _ _ __ ___   __ _ _ __ ___
| '_ \| | | | '_ ` _ \ / _` | '__/ __|
| |_) | |_| | | | | | | (_| | | | (__
| .__/ \__, |_| |_| |_|\__,_|_|  \___|
|_|    |___/

Build Status

pymarc是一个python库,用于处理在 MARC21。它应该在 Python2.x和3.x. 马克唱片公司。它主要设计成一个紧急弹射座椅, 从marc中获取数据资产 代表。然而多年来它被用来创造 修改marc记录,因为尽管 repeated calls让它死去 作为一种形式,马克看起来像一个僵尸一样快乐地生活着。

下面是一些常见的例子,说明您可能希望如何使用pymarc。如果 你遇到了一个你认为应该在这里的例子,请发送 拉取请求。

读数

通常你会有一些marc数据并且想要提取数据 从它。下面是一个读取一批记录并打印出来的示例 标题。如果您好奇,这个示例使用批处理文件 在Pymarc存储库中提供:

frompymarcimportMARCReaderwithopen('test/marc.dat','rb')asfh:reader=MARCReader(fh)forrecordinreader:print(record.title())
The pragmatic programmer : from journeyman to master /
Programming Python /
Learning Python /
Python cookbook /
Python programming for the absolute beginner /
Web programming : techniques for integrating Python, Linux, Apache, and MySQL /
Python programming on Win32 /
Python programming : an introduction to computer science /
Python Web programming /
Core python programming /
Python and Tkinter programming /
Game programming with Python, Lua, and Ruby /
Python programming patterns /
Python programming with the Java class libraries : a tutorial for building Web
and Enterprise applications /
Learn to program using Python : a tutorial for hobbyists, self-starters, and all
who want to learn the art of computer programming /
Programming with Python /
BSD Sockets programming from a multi-language perspective /
Design patterns : elements of reusable object-oriented software /
Introduction to algorithms /
ANSI Common Lisp /

一个pymarc.Record对象有一些方便的方法,比如title来获取 书目记录的位,其他包括:authorisbnsubjectslocationnotesphysicaldescriptionpublisherpubyear。但是 实际上,要处理marc数据,您需要理解数字字段标记 以及用于指定各种信息位的子字段代码。在那里 比这些方法提供的访问权限隐藏在marc记录中的要多得多。 例如,title方法从245字段提取信息, 子字段ab。您可以像这样访问245a

print(record['245']['a'])

有些领域像学科可以重复。在这种情况下,你会想使用 get_fields以获得所有的pmarc.Field对象,然后可以 进一步互动:

forfinrecord.get_fields('650'):print(f)

如果你对marc fields还不熟悉,那么Understanding MARC是一本很好的入门读物,而国会图书馆的MARC 21 Formats页面在你了解了基础知识之后,是一个很好的参考。

写作

下面是一个创建记录并将其写入文件的示例。

frompymarcimportRecord,Fieldrecord=Record()record.add_field(Field(tag='245',indicators=['0','1'],subfields=['a','The pragmatic programmer : ','b','from journeyman to master /','c','Andrew Hunt, David Thomas.']))withopen('file.dat','wb')asout:out.write(record.as_marc())

更新

更新的工作原理是一样的,你读入,修改,然后写出来 再次:

frompymarcimportMARCReaderwithopen('test/marc.dat','rb')asfh:reader=MARCReader(fh)record=next(reader)record['245']['a']='The Zombie Programmer'withopen('file.dat','wb')asout:out.write(record.as_marc())

json和xml

如果你发现自己使用了大量的marc数据,并将其分发出去,你可以 通过使用json或xml序列化,让其他开发人员更加高兴。 Pymarc支持这两种方法。这里的主要优点是utf8字符 使用了编码,而不是令人沮丧的古老的marc8编码。阿尔索 他们将能够使用json和xml工具来获取他们想要的数据。 一些疯狂的marc处理库,嗯,pymarc。

安装

您可能只想使用pip安装pymarc:

pip install pymarc

如果您想下载并安装最新的源代码,您需要git:

git clone git://github.com/edsu/pymarc.git

你还需要setuptools。一旦源代码和设置工具运行了pymarc测试 套件,以确保分发的内容井然有序:

python setup.py test

然后安装:

python setup.py install

支架

pymarc开发人员鼓励您在需要帮助时加入pymarc Google Group。另外,请使用github上的issue tracking提交功能请求或错误报告。如果您有抓挠的欲望,请抓挠它,然后在Github上发送合并请求。

如果你开始和马克一起工作,你可能会觉得你需要精神上的支持 除了技术支持。这是#code4libFreenode上的频道对两者都是一个好地方。

版权所有

版权所有(c)2005-2016 Gabriel Farrell,Mark Matienzo,Geoffrey Spear,Ed Summers

许可证

BSD

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
servlets Java EE+GlassFish:如果用户在其他地方登录,则强制用户注销   java在不更改源代码的情况下添加钩子   安卓 Java TextView Onclick()返回表达式错误   java Excel文件未使用Apache存储内部内存   java getRowCount()和getSelectedColumn()不起作用   无法在java中生成视图绑定。util。Android Gradle插件2.1的NoTouchElementException   Java中的类型转换运算符百分比计算为零   主java中的调用方法   java在Javasound中播放多个示例   java如何知道webDriver成功打开URL   java jmock,每次调用时返回新对象   eclipse使用Java在Selenium WebDriver中生成可执行文件   macos捆绑Java OS X应用程序默认为MacRoman编码   java我应该把我的休息网关变成一个图书馆吗?   java Eclipse插件:查找包含子字符串的行号无效   Java IOException:在Linux上发送UDP数据包时没有可用的缓冲区空间   java无法解析jaxbxjc2中的名称“xjc:globalJavaType”。2.52.罐子   java是否有HibernateAPI来检查是否创建了数据库?