Python Forum
coma separator is printed on a new line for some reason
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
coma separator is printed on a new line for some reason
#3
I guess prod has at the end of the str a newline character.
You can strip it. I often use rstrip to remove only on the right side of the str whitespace. A newline character is also seen as a whitespace.

delimiter = ","
product_name = "Test 123"
product_name_newline = "Test 123\n"



print("Test without newline")
print(f"{product_name}{delimiter}")
print()

print("Test with newline at the end of the str")
print(f"{product_name_newline}{delimiter}")
print()

print("Test with newline at the end of the str and the prevention")
print(f"{product_name_newline.rstrip()}{delimiter}")
print()
tester_V likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: coma separator is printed on a new line for some reason - by DeaD_EyE - Feb-02-2024, 07:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Exception printed twice rwestebbe 2 898 Sep-02-2024, 09:45 PM
Last Post: DeaD_EyE
  Printing a raw string with a folder separator at the end, duplicates the separator krulah 5 2,486 Nov-28-2022, 12:41 PM
Last Post: snippsat
  How can histogram bins be separated and reduce number of labels printed on x-axis? cadena 1 2,049 Sep-07-2022, 09:47 AM
Last Post: Larz60+
  Numpy savetxt, how save number with decimal separator SpongeB0B 1 4,505 May-10-2020, 01:05 PM
Last Post: ThomasL
  Reason of the output himanshub7 2 2,927 Apr-28-2020, 10:44 AM
Last Post: TomToad
  Reverse printed words hindubiceps 7 4,447 Apr-21-2020, 05:19 PM
Last Post: deanhystad
  Code used to work, not anymore for no apparent reason? chicagoxjl 1 2,602 Jan-08-2020, 05:05 PM
Last Post: jefsummers
  I get "None" at the end of my printed result. dyshkant 3 3,808 Sep-06-2019, 06:31 PM
Last Post: dyshkant
  bytes not being printed as expected Skaperen 2 3,665 Aug-27-2019, 05:33 AM
Last Post: Skaperen
  Syntax error for a reason I don't understand DanielCook 2 3,164 Aug-07-2019, 11:49 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020