Python Forum
Python convert multi line into single line formatted string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python convert multi line into single line formatted string
#1
Hi, Pls help me on the below issue. I have tried a lot, but not getting correct format.

I have a python flask application where I am getting inputs from a User and POST to JIRA application to create ticket.

One of my field is description and it is a multi-line field.

Expected Input: [in description field, which is multi-line]
testinput1
testinput2
testinput3

Expected output format: [Need in this format for JIRA post rest api process]
\\ntestinput1\\ntestinput1\\ntestinput1\\n

I tried so far,
b=request.form['description'] # I gave multi-line inputs in this field thru front end UI screen
a='''{b}'''.format(b=b)
print(a)
out=a.replace("\n", "\\n")
print(out)
Reply
#2
What is the behavior you are observing and what is your expectation?
Reply
#3
(Dec-23-2019, 06:48 AM)Malt Wrote: What is the behavior you are observing and what is your expectation?

Currently, I am getting an output like below

#input - multi line input thru front end UI screen
t12
t14

#output
\12
t14
Expectation:

#to support jira rest api format, I need formatted string like below
\\nt12\\nt14\\n

I just tried like below and got expected output (able to post successfully in JIRA to create ticket)
Pls let me know, if any other efficient way to handling this string format.

#get input from UI screen and place in multi line quote string
input_desc='''{}'''.format(request.form['description'])
#convert each line into array list
format_desc=input_desc.splitlines()

description=""
for i in format_desc:
  description=description+i+'\\n'
Output:
testline1\ntestline2\ntestline3\n
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  No new line from print in a browser Lou 13 1,366 Dec-01-2025, 06:39 PM
Last Post: noisefloor
  cannot unpack non-iterable int object in urllib3/util/wait.py", line 85, ping_chen_ibm_us 2 931 Aug-01-2025, 02:05 PM
Last Post: ping_chen_ibm_us
  [SOLVED] Why does regex fail cleaning line? Winfried 7 4,937 Jul-11-2025, 11:52 PM
Last Post: Pedroski55
  Convert any Python expression to a string voidtrance 2 1,130 Jun-23-2025, 07:06 AM
Last Post: DeaD_EyE
  I am a newbie I like to use the command line Mikel2025 1 1,063 Jun-13-2025, 03:20 PM
Last Post: Gribouillis
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 13 36,670 May-20-2025, 12:26 PM
Last Post: hanmen9527
  Βad Input on line 12 Azdaghost 5 2,237 Apr-19-2025, 10:22 PM
Last Post: Azdaghost
Question [SOLVED] [Beautiful Soup] Move line to top in HTML head? Winfried 0 967 Apr-13-2025, 05:50 AM
Last Post: Winfried
  Insert command line in script lif 4 2,200 Mar-24-2025, 10:30 PM
Last Post: lif
  Entry field random pull from list, each return own line Bear1981 6 1,940 Feb-25-2025, 06:09 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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