Created
May 25, 2021 19:35
-
-
Save zeph1rus/a6404ca68b52d32dc2a3b0674dfb466d to your computer and use it in GitHub Desktop.
Python f string none value shows as 'None' in string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rnn(i: str) -> str: | |
""" | |
Python hack. In f-strings, python will interpret '' or "" as "None" instead of, well None, and | |
thus you get None in text which helps nobody in url strings. This uses an iterator join on a | |
list comprehension to ensure we return no text at all if the value is none. Thanks python. | |
:param i: String that may be None or "" or an actual value | |
:type i: str | |
:return: the text if it is there else, specifically '' (not None or null like object) | |
:rtype: str | |
""" | |
return ''.join(a for a in {i} if i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment