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
  Line graph with two superimposed lines sawtooth500 4 307 Apr-02-2024, 08:56 PM
Last Post: sawtooth500
  How to add multi-line comment section? Winfried 1 193 Mar-24-2024, 04:34 PM
Last Post: deanhystad
  break print_format lengthy line akbarza 4 359 Mar-13-2024, 08:35 AM
Last Post: akbarza
  Reading and storing a line of output from pexpect child eagerissac 1 4,230 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  coma separator is printed on a new line for some reason tester_V 4 482 Feb-02-2024, 06:06 PM
Last Post: tester_V
  problem with spliting line in print akbarza 3 375 Jan-23-2024, 04:11 PM
Last Post: deanhystad
  Unable to understand the meaning of the line of code. jahuja73 0 303 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Receive Input on Same Line? johnywhy 8 704 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  Reading in of line not working? garynewport 2 832 Sep-19-2023, 02:22 PM
Last Post: snippsat
  'answers 2' is not defined on line 27 0814uu 4 726 Sep-02-2023, 11:02 PM
Last Post: 0814uu

Forum Jump:

User Panel Messages

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