diff options
author | Kurt Keller <Kurt@pinboard.jp> | 2019-11-04 23:01:20 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2019-11-09 14:07:46 +0100 |
commit | 388bac9d3df5e40d7d7f8bb112f114d05f10b7b5 (patch) | |
tree | dd90f3139d823d069c0e03307c8720610febfe1e /stdnum | |
parent | a45d4f705e7f59ee3e6314491c47199d0d5aa581 (diff) |
Add format to iso11649
Closes https://github.com/arthurdejong/python-stdnum/pull/171
Diffstat (limited to 'stdnum')
-rw-r--r-- | stdnum/iso11649.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/stdnum/iso11649.py b/stdnum/iso11649.py index f176852..d0b784f 100644 --- a/stdnum/iso11649.py +++ b/stdnum/iso11649.py @@ -41,6 +41,8 @@ True Traceback (most recent call last): ... InvalidChecksum: ... +>>> format('RF18539007547034') +'RF18 5390 0754 7034' """ from stdnum.exceptions import * @@ -73,3 +75,14 @@ def is_valid(number): return bool(validate(number)) except ValidationError: return False + + +def format(number): + """Format the number provided for output. + + Blocks of 4 characters, the last block can be less than 4 characters. See + https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf chapter + 3.6.2. + """ + number = compact(number) + return ' '.join(number[i:i + 4] for i in range(0, len(number), 4)) |