Hi,
I'm new with Python but I work with MARC since some years.
I'm working about a institutional repository where metadata of all publications stored in MARCXML (repository based on Fedora Commons)
So I try to use "pymarc" to easily manage metadata.
At this time, I need to delete some subfields. No problem method exists in pymarc.files ...
But my fields can contains multiple same code subfields. By example :
<marc:field tag="955" ind1=" " ind2=" "> <!-- used to store document type and subtypes -->
<marc:subfield code="a">Periodical article</marc:subfield> <!-- document type -->
<marc:subfield code="b">Published</marc:subfield> <!-- document subtype -->
<marc:subfield code="b">Clinical trial</marc:subfield> <!-- document subtype -->
</marc:field>
In my case, I need to delete "Clinical trial". If I use "delete_subfield" method, I can't be sure that the I will delete the correct subfield.
So I wrote a little method to delete subfield depending of the value :
def delete_sepcific_subfields(field, code, value):
all_idx = [i for i in range(len(field.subfields)) if (i % 2 == 0 and field.subfields[i] == code and field.subfields[i+1] == value)]
for idx in all_idx:
field.subfields.pop(idx+1) #pop value
field.subfields.pop(idx) #pop code
return field
This method is working fine, but I would know if it's a best way to do that using basic "pymarc" package ?
As I'm very lazy :-) I would like to know if is it a chance to include a such method into "pymarc" rather than copy-paste this code on all my project.
Thanks (and sorry for my english ^^)
Regards
Renaud