简体   繁体   中英

New line with invisible character not makes a line break?

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM