简体   繁体   中英

How to remove brackets from output?

I'm trying to display the output of the following code example without the brackets (as you can see in my current output below) I want to display the data in the textarea field as simple text with line break.

Does anyone know how to do this? I can't seem to find a solution without working on my corresponding HTML file. Thanks in advance!

@app.route('/show_user', methods=['GET', 'POST'])
def show_user():
    form = myform()
    result = session.query(User.username).all()
    form.textarea.data = result
    return render_template('index.html', title='users.', user=current_user, form=form)

CURRENT OUTPUT: [('bla',), ('bli',)] WANTED OUTPUT: bla bli

I use flask and sqlalchemy.

It looks like result is a list of tuples of length 1. This should work:

result = [('bla',), ('bli',)]
result_as_text = '\n'.join([x[0] for x in result])
print(result_as_text)

Output:

bla
bli

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM