Python 2.7 Python字符串变量值我可以连接这些值并在函数中返回值吗

Python 2.7 Python字符串变量值我可以连接这些值并在函数中返回值吗,python-2.7,beautifulsoup,Python 2.7,Beautifulsoup,我有下面的函数和一些打印语句。在每个打印语句中,我希望返回它的值,以便我可以使用它并将其添加到我的电子邮件代码中,该代码将把每个字符串文本发送到电子邮件中 我试图将每个字符串连接成一个变量,并在函数底部返回它。 e、 g 我得到一个错误: File "E:/test_runners 2 edit project in progress add more tests/selenium_regression_test_5_1_1/Email/email_selenium_report.py"

我有下面的函数和一些打印语句。在每个打印语句中,我希望返回它的值,以便我可以使用它并将其添加到我的电子邮件代码中,该代码将把每个字符串文本发送到电子邮件中

我试图将每个字符串连接成一个变量,并在函数底部返回它。 e、 g

我得到一个错误:

    File "E:/test_runners 2 edit project in progress add more tests/selenium_regression_test_5_1_1/Email/email_selenium_report.py", line 30, in <module>
    report.extract_data_from_report_htmltestrunner()
  File "E:\test_runners 2 edit project in progress add more tests\selenium_regression_test_5_1_1\Email\report.py", line 400, in extract_data_from_report_htmltestrunner
    p_text = p_start_time + p_duration + p_status
TypeError: unsupported operand type(s) for +: 'Tag' and 'Tag'
在每个print语句中,如何将其作为字符串变量返回? 一旦我把它退回,我可以将它包含在我的电子邮件代码的消息部分

即使是for循环中的print语句,我也希望以字符串变量的形式返回它

print(" ".join([td.text for td in row.find_all("td")[1:-1]]))
谢谢,里亚兹

p_text=p_开始时间+p_持续时间+p_状态

在此表达式中,所有操作数都是不能用
+
粘合在一起的。您可以将它们转换为字符串,然后连接:

p_text = "".join(map(str, [p_start_time, p_duration, p_status]))

谢谢,这个有用。我用html标记获得输出

开始时间:2016-08-12 11:57:33

持续时间:0:48:09.007000

状态:Pass 75

我能去掉html标签吗?@Riazlahani啊,有点误解了这个问题。在每个“标记”实例上调用“.get_text()”。明白了。非常感谢你的帮助。
print(" ".join([td.text for td in row.find_all("td")[1:-1]]))
p_text = "".join(map(str, [p_start_time, p_duration, p_status]))