如何解决如何在将我的变量附加到+=python 中的另一个变量之前添加新行?
我使用 Rasa X 作为我的前端。我看不出这与它有什么关系,但我想我会提到它以防万一。无论如何,我有一个变量正在从我的 Excel 工作表中收集单元格值。我正在使用循环语句将值添加到我的变量“requested_information”。循环完成后,我将字符串“\n”和我的变量“missing_info”添加到其中。打印requested_information 时,新行不在那里。这是文本结果:
这是我的代码:
for column in load_data.column_names:
project_name_cell = str(sheet["B{}".format(row)].value)
main_cell = str(sheet["" + column + "{}".format(row)].value)
if project_id_provided == False:
requested_information += "The " + load_data.column_names[column] + " for project " + project_name_cell + " is " + main_cell + ".\n"
else:
if main_cell == "n/a" or main_cell == None:
missing_info_list.append(load_data.column_names[column])
continue
if column == "E" or column == "G" or column == "I" or column == "J":
requested_information += "The " + load_data.column_names[column] + " is " + phone_formatter(main_cell) + ".\n"
elif column == "M" or column == "N" or column == "O" or column == "P":
requested_information += "The " + load_data.column_names[column] + " is " + "${:,.2f}".format(float(main_cell)) + ".\n"
elif column == "Q":
requested_information += "The " + load_data.column_names[column] + " is " + "{:.2%}".format(float(str(main_cell))) + ".\n"
elif column == "D" or column == "F" or column == "H":
if main_cell != None or main_cell == "":
if rasa_actions_settings.include_email_functions == False:
requested_information += ("The " + load_data.column_names[column] + " is " + main_cell + ".\n")
#else:
##NOTE - Uncomment procedures to enable personal emails being attached to the employees' contact info
#email = email_functions.GetEmailAddress(main_cell)
#firstName = main_cell.split(" ")
#requested_information += ("The " + load_data.column_names[column] + " is " + main_cell + " and " + firstName[0] + "'s email address is " + email + ".\n")
elif column == "R":
date = main_cell.split(" ")[0]
requested_information += "The " + load_data.column_names[column] + " is " + "{}/{}/{}".format(date[5:7],date[8:],date[0:4]) + ".\n"
else:
requested_information += "The " + load_data.column_names[column] + " is " + main_cell + ".\n"
project_id_provided = True
if len(missing_info_list) > 0:
missing_info += " There doesn't seem to be any information for the following catagories: \n"
first_item_used = False
for missing_catagory in missing_info_list:
if first_item_used == False:
first_item_used = True
missing_info += missing_catagory
else:
missing_info += "," + missing_catagory
if len(missing_info_list) == 1:
missing_info = " There doesn't seem to be any information for the " + missing_info_list[0]
requested_information += "\n" + missing_info + "." #NOTE - HERE,THE STRINGS ARE COMBINED
dispatcher.utter_message(requested_information)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。