New line with invisible character not makes a line break?

1.8k Views Asked by At

I have a string that shows like that:

def function():
  my_string = """Balabala
  -
  Blala2: lala
  -
  Blala#End
  """

All the empty lines have that invisible character (character: ⠀).

When I print that string, I get:

Balabala
-Blala2: lala
-Blala#End

The - is an invisible character. Stackoverflow not allow that invisible character. What python should print:

Balabala
-
Balala2: lala
-
Blala#End

Does anyone have any advice for me or a solution?

EDIT: I use that string for Instagram Image description. Instagram not allow line breaks without a character. Because of that restriction, I searched for an invisible character. Now I want to implement that invisible character in my string.

1

There are 1 best solutions below

3
On

You can filter out the invisible characters with a list comprehension:

my_string = """Balabala

Blala2: lala

Blala#End
"""

my_string = ''.join(char for char in my_string if char.isascii())

print(my_string)

Output:

Balabala

Blala2: lala

Blala#End