isbn_truncate#
- isbn_truncate(value, *, element=..., hyphenate=True, strict=False)#
Truncates the ISBN after the specified element.
This function truncates the ISBN to the specified element. If an ISBN-10 is passed, it is converted to an ISBN-13 beforehand.
Added in version 0.3.0.
Warning
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
- Parameters:
- valuestr
The value to be truncated.
- elementIsbnElement, default = ‘registrant’
The element (
prefix,group,registrant,publication, orcheck-digit) up to which the cut should be made.- hyphenatebool, default=True
Whether hyphens should be used to separate the elements or not.
- strictbool, default=False
If set, a
ValueErroris raised if an invalid ISBN is passed, otherwiseNoneis returned.
- Returns:
- str
The truncated ISBN.
Examples
>>> from marc21_learn.pid import isbn_truncate >>> >>> isbn_truncate("978-3-10-031815-2", element="prefix") '978' >>> isbn_truncate("978-3-10-031815-2", element="group") '978-3' >>> isbn_truncate("978-3-10-031815-2", element="registrant") '978-3-10' >>> isbn_truncate("978-3-10-031815-2", element="publication") '978-3-10-031815' >>> isbn_truncate("978-3-10-031815-2", element="check-digit") '978-3-10-031815-2'