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,
1
2
3
4
5
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

1
2
3
4
5
6
7
#input - multi line input thru front end UI screen
t12
t14
 
#output
\12
t14
Expectation:

1
2
#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.

1
2
3
4
5
6
7
8
#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:
1
testline1\ntestline2\ntestline3\n
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Βad Input on line 12 Azdaghost 5 1,343 Apr-19-2025, 10:22 PM
Last Post: Azdaghost
Question [SOLVED] [Beautiful Soup] Move line to top in HTML head? Winfried 0 316 Apr-13-2025, 05:50 AM
Last Post: Winfried
  Insert command line in script lif 4 1,046 Mar-24-2025, 10:30 PM
Last Post: lif
  Entry field random pull from list, each return own line Bear1981 6 850 Feb-25-2025, 06:09 AM
Last Post: Pedroski55
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 12 28,443 Feb-13-2025, 04:48 AM
Last Post: tomhansky
  How to revert back to a previous line from user input Sharkenn64u 2 1,065 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  Pandas - error when running Pycharm, but works on cmd line zxcv101 2 2,496 Sep-09-2024, 08:03 AM
Last Post: pinkang
  Simplest way to run external command line app with parameters? Winfried 2 1,365 Aug-19-2024, 03:11 PM
Last Post: snippsat
  Printing the code line number arbiel 6 1,707 Jun-30-2024, 08:01 AM
Last Post: arbiel
  How to add multi-line comment section? Winfried 2 1,419 Jun-04-2024, 07:24 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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