Bottom Page

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)
Quote
#2
What is the behavior you are observing and what is your expectation?
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Ignore first few letters of a line when reading file. ShakeyPakey 16 367 May-30-2020, 02:17 PM
Last Post: BitPythoner
  Int error on line 70 CrazyMakes 3 264 May-23-2020, 05:09 AM
Last Post: buran
  could not convert string to float player1681 4 246 May-22-2020, 12:10 PM
Last Post: buran
  some help with reading line from CMD on PI korenron 4 162 May-21-2020, 08:25 AM
Last Post: korenron
  Pyinstaller create this error :“File ”multiprocessing\connection.py“, line 691 Formationgrowthhacking 2 160 Apr-30-2020, 10:26 AM
Last Post: buran
  print only last matched line tester_V 24 810 Apr-30-2020, 05:16 AM
Last Post: deanhystad
  Jupiter Notebook does not show output line Renym 3 159 Apr-26-2020, 11:21 AM
Last Post: jefsummers
  item from a line to list however when i print the line instead of words i get letters Sutsro 5 160 Apr-22-2020, 02:39 PM
Last Post: deanhystad
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 128 Apr-22-2020, 01:01 PM
Last Post: deanhystad
  Delete all contents of a file from the fifth line? PythonNPC 1 188 Apr-18-2020, 09:16 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)