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
  beginner text formatting single line to column jafrost 4 305 Apr-28-2021, 07:03 PM
Last Post: jafrost
Question convert unlabeled list of tuples to json (string) masterAndreas 4 216 Apr-27-2021, 10:35 AM
Last Post: masterAndreas
  If match not found print last line tester_V 2 192 Apr-26-2021, 05:18 AM
Last Post: tester_V
  How to input & output parameters from command line argument shantanu97 1 198 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  Parse String between 2 Delimiters and add as single list items lastyle 5 260 Apr-11-2021, 11:03 PM
Last Post: lastyle
  Convert String of an int array to a Numpy array of ints mdsousa 5 439 Apr-08-2021, 08:00 PM
Last Post: mdsousa
  How to make input come after input if certain line inserted and if not runs OtherCode Adrian_L 6 426 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
Exclamation Why there's a 'blank line' on CSV file? brunolelli 4 321 Mar-25-2021, 03:43 AM
Last Post: buran
  how to connect mysql from txt 1 line goes good but not all lines in text kingceasarr 4 318 Mar-24-2021, 05:45 AM
Last Post: buran
  Printing a specific line from a JSON serpiente 4 483 Mar-14-2021, 07:27 PM
Last Post: buran

Forum Jump:

User Panel Messages

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