Skip to content

Commit

Permalink
Add None/nan tolerant string join function
Browse files Browse the repository at this point in the history
  • Loading branch information
ejohb committed Jan 20, 2025
1 parent 6f749f0 commit 68196f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions fmtr/tools/string_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from string import Formatter
from typing import List

from fmtr.tools.datatype_tools import is_none

ELLIPSIS = '…'
formatter = Formatter()

Expand Down Expand Up @@ -106,6 +108,18 @@ def flatten(raw):
return text


def join(strings, sep=' '):
"""
Join a list of strings while removing Nones
"""

lines = [string for string in strings if not is_none(string) and string != '']
text = sep.join(str(line) for line in lines)
return text


class Mask:
"""
Expand Down
2 changes: 1 addition & 1 deletion fmtr/tools/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.11
1.0.12

0 comments on commit 68196f8

Please sign in to comment.