Dollar sign characters in text shifted to "{dollar}"

72 views
Skip to first unread message

Ben W.

unread,
Mar 1, 2024, 10:19:35 AM3/1/24
to pymarc Discussion
Pymarc doesn't appear to have a way to 'escape' special characters in the text used to generate MARC data, so if a dollar sign appears in the text, pymarc changes the sign to the string of "{dollar}" (that is, the string 'dollar' surrounded by curly braces). 

Are there any workarounds folks are using to keep this from happening?

Andrew Hankinson

unread,
Mar 1, 2024, 10:37:06 AM3/1/24
to pym...@googlegroups.com
What would you suggest as the alternative behaviour? We use "__DOLLAR__", but it's still the same principle. The $ symbol can't appear in the text, and there's not really any concept of escape codes (e.g., "\\$") that would work in MARC, as far as I know.

-Andrew 

On 1 Mar 2024, at 16:19, Ben W. <wreck...@gmail.com> wrote:

Pymarc doesn't appear to have a way to 'escape' special characters in the text used to generate MARC data, so if a dollar sign appears in the text, pymarc changes the sign to the string of "{dollar}" (that is, the string 'dollar' surrounded by curly braces). 

Are there any workarounds folks are using to keep this from happening?

--
You received this message because you are subscribed to the Google Groups "pymarc Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymarc+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pymarc/bd201081-ef66-4306-b4e7-687c2e36e4d4n%40googlegroups.com.

Ed Summers

unread,
Mar 1, 2024, 10:42:17 AM3/1/24
to pym...@googlegroups.com
Hi Ben,

I feel silly for asking this since Andrew understood what you were asking, but could you provide an example using pymarc of what you are talking about here?

//Ed

> On Mar 1, 2024, at 10:19 AM, Ben W. <wreck...@gmail.com> wrote:
>
> Pymarc doesn't appear to have a way to 'escape' special characters in the text used to generate MARC data, so if a dollar sign appears in the text, pymarc changes the sign to the string of "{dollar}" (that is, the string 'dollar' surrounded by curly braces).
>
> Are there any workarounds folks are using to keep this from happening?
>

Andrew Hankinson

unread,
Mar 1, 2024, 10:45:25 AM3/1/24
to pym...@googlegroups.com
I think the problem, as I understood it, is that the dollar sign can't actually appear in the field values... So you can't have "$aThis Book Costs $1.99" since most MARC parsers will interpret that as the start of a $1 field.

(Like I said, we have the same problem so I'm familiar with it...)

-Andrew
> To view this discussion on the web visit https://groups.google.com/d/msgid/pymarc/7BB73A5C-B825-43D6-A58C-905E86BF49FC%40pobox.com.

Ben W.

unread,
Mar 1, 2024, 11:04:24 AM3/1/24
to pymarc Discussion
That's exactly it, Andrew, thanks.

Using Andrew's example, that text would come out as "$aThis Book Costs {dollar}1.99". Using an escape character only adds the slash but doesn't change anything, so submitting Subfield(code="a", value="This Book Costs \$1.99") would come out in MARC as "$aThis Book Costs \{dollar}1.99".

Ed Summers

unread,
Mar 1, 2024, 11:05:02 AM3/1/24
to pym...@googlegroups.com

> On Mar 1, 2024, at 10:45 AM, Andrew Hankinson <andrew.h...@gmail.com> wrote:
>
> I think the problem, as I understood it, is that the dollar sign can't actually appear in the field values... So you can't have "$aThis Book Costs $1.99" since most MARC parsers will interpret that as the start of a $1 field.
>
> (Like I said, we have the same problem so I'm familiar with it...)

But pymarc doesn’t enforce that, right?

```
from pymarc import Record, Field, Subfield, MARCReader

rec = Record()
rec.add_field(Field(
tag="245",
indicators=["0", "1"],
subfields=[
Subfield(code="a", value="Huckleberry $Finn")
]
))

open('rec.dat', 'wb').write(rec.as_marc())

rec = next(MARCReader(open('rec.dat', 'rb')))
print(rec['245']['a’])
```

It seems like it might be possible to customize pymarc for a particular downstream parsing library?

//Ed

Ben W.

unread,
Mar 1, 2024, 11:39:49 AM3/1/24
to pymarc Discussion
Great point, Ed. If I use Notepad++ to view the MRC file, we can see that it's the parser making the change (in my case, that would be MARCEdit): 

marc_dollar_delimiter.png

I think we'll just have to use "__DOLLAR__" or similar for the time being.

Ed Summers

unread,
Mar 1, 2024, 11:57:08 AM3/1/24
to pym...@googlegroups.com
Ahah! Does MARCEdit prefer $ to be encoded in a particular way?

Ben W.

unread,
Mar 1, 2024, 12:18:58 PM3/1/24
to pymarc Discussion
LOL. I should be clearer, Ed: Our ILS system is Aleph/Ex Libris, so that will be the parser with the final say on how the records are maintained and displayed, whereas MARCEdit is the utility knife I use for reading/compressing/decompressing MARC data. In this particular case, it's probably easier for us to use Andrew's solution so that our ILS Team can run whatever processes they need to in order to properly store/display the records.
Reply all
Reply to author
Forward
0 new messages