I am working with python. I want to convert a single item list to a multiline-string.
I fetched emails string from database. All emails are store as a list items(between ' ').
emails strings are have special-characters and also symbols like[ ' " , @ ( * & # ] When I fetch list items(emails) ONE-BY-ONE at that time my string is stored in ' ' so when ' is comes in string at that time string is broken in to multiple parts.
so, I want to store one list item(email) as multiline-string(''' ''').
string=[]
for row in email_records:
string.append(row[1])
print(string)
output get like this:-
['d "jkssjfdsd<sdsdfg @flkj'dlkj'hcjkhkg d#cgcgcg/jcgj'jjjx dfdffh# \fjhfghjj',
'd "jkssjfdsd<sdsdfg @flkj'dlkj'hcjkhkg d#cgcgcg/jcgj'jjjx dfdffh# \fjhfghjj',
'd "jkssjfdsd<sdsdfg @flkj'dlkj'hcjkhkg d#cgcgcg/jcgj'jjjx dfdffh# \fjhfghjj',
'd "jkssjfdsd<sdsdfg @flkj'dlkj'hcjkhkg d#cgcgcg/jcgj'jjjx dfdffh# \fjhfghjj']
I fetch all items one-by-one and find substring at that time it is not working because when ' is comes in string at that time string is broken in to multiple parts.
for massage in string:
print(massage)
output get like this:-
'd "jkssjfdsd<sdsdfg @flkj'dlkj'hcjkhkg d#cgcgcg/jcgj'jjjx dfdffh# \fjhfghjj'
output wont like this:-
'''d "jkssjfdsd<sdsdfg @flkj'dlkj'hcjkhkg d#cgcgcg/jcgj'jjjx dfdffh# \fjhfghjj'''
CodePudding user response:
In python, the print
command prints the string (or str(obj)
) without the '
s.
However, you can print them yourself:
for massage in string:
print(f"'''{massage}'''")