python - 如何在 python 中将我的变量与另一个变量附加(+=)之前添加新行?
问题描述
我使用 Rasa X 作为我的前端。我看不出这与它有什么关系,但我想我会提到它以防万一。无论如何,我有一个变量正在从我的 excel 表中收集单元格值。我正在使用循环语句将值添加到我的变量“requested_information”。循环完成后,我将字符串“\n”和我的变量“missing_info”添加到它。打印请求信息时,新行不在其中。这是文本结果:
这是我的代码:
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)
解决方案
推荐阅读
- swift - 尺寸变化标签的约束
- ftp - 将所有文件从 FTP 服务器传输到 Artifactory Generic repo
- java - Rxjava - 链 observables
- javascript - console.log 没有在 Chrome 中打印任何内容
- sql - Oracle Apex 5.0:使用基于页面项目的 WHERE IN 子句填充 IR
- ruby-on-rails - 延迟作业将每个请求两次插入后端?
- i2c - 如何在 Android Things 上运行 Ssd1351?
- jenkins - Jenkinsfile 比较变量
- spring-boot - 运行测试但不是主应用程序时没有类型存储库的合格 bean
- mongodb - 如何在 db.collection.aggregation() 中输入变量?