Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何用换行符分隔数据_Python_Html_Wsgi - Fatal编程技术网

Python 如何用换行符分隔数据

Python 如何用换行符分隔数据,python,html,wsgi,Python,Html,Wsgi,我试图弄清楚如何分离HTML页面上显示的数据,该页面来自python中的元组 Python: callComments = (interface.list_comments(db,10)) content = { comments': '<p>%s</p>' % commentString, } 但我希望它输出如下: (13, 'mary@where.com', 'hello', ' amet, consectetur ad

我试图弄清楚如何分离HTML页面上显示的数据,该页面来自python中的元组

Python:

    callComments = (interface.list_comments(db,10))

    content = { comments': '<p>%s</p>' % commentString,
              }
但我希望它输出如下:

(13, 'mary@where.com', 'hello', ' amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua. Ut')

(12, 'mary@where.com', 'hello', 'orem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor i')

(11, 'jim@there.com', 'hello', 'consectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip\nex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat\nnulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui of')

最简单、最有效的方法是什么?

您需要以某种方式在元组上循环。最好的方法取决于您使用的工具,特别是模板语言和框架

如果您没有使用模板语言或框架,那么正确的答案是:“使用一个好的webframework,使用某种模板语言”

如果您出于某种原因拒绝使用良好做法,请执行以下操作:

callComments = interface.list_comments(db,10)

content = { 'comments': ' '.join('<p>%s</p>' % repr(x) for x in callComments),
          }
callComments=interface.list_comments(db,10)
content={'comments':''.join('%s

'%repr(x)代表callComments中的x), }
1。您的Python有语法错误。2.您没有真正解释如何呈现HTML。您使用的是什么框架/模板语言?这是一个很难回答的问题吗?这种输出有点愚蠢。这不是你真正想要的,是吗?我刚刚意识到,你甚至没有显示完整的代码。在当前状态下,这个问题不是真正可以回答的,它包含了太多的猜测。这非常有效!我是新来的,所以很抱歉我没有提供足够的信息。你能解释一下这到底是怎么回事吗?我宁愿学习,也不愿得到答案。谢谢你的时间@用户2288946:如果你回答我上面的问题,我会告诉你的
(13, 'mary@where.com', 'hello', ' amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua. Ut')

(12, 'mary@where.com', 'hello', 'orem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor i')

(11, 'jim@there.com', 'hello', 'consectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip\nex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat\nnulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui of')
callComments = interface.list_comments(db,10)

content = { 'comments': ' '.join('<p>%s</p>' % repr(x) for x in callComments),
          }