【发布时间】:2020-04-26 05:15:34
【问题描述】:
抱歉,如果这是重新发布。我正在尝试使用 continue 变量和 if/else 语句编写一个 while 循环。我的问题是我的continue 变量被忽略了,到目前为止我找不到问题。到目前为止,我已将 while continues == 'y' 条件移到 else 块中,现在我对为什么忽略此 var 感到有些困惑。
代码:
def add_to_existing_file(data):
# data[0]-api response
# data[1]-city
# infile-file object returned from openFile()
# file_name- file name string. check filetype & report version.
continues = 'y' # set up continue variable
while continues == 'y':
file_name = input("Enter File Path to file to be appended: ") # get file from user
if file_name is False:
print("Now Creating Excel File..") # create condition for no user response.
return # if empty response exit function
else:
infile = appends.openFile(file_name) # open file to work with. Returns file object.
added_data = appends.journal_report_1_to_df(infile, file_name, data[0], data[1]) # append selected file to existing df
continues = input("Do you want to append another file? Y or N").lower() # check if new file
return added_data # return new df w/appended data
【问题讨论】:
标签: python-3.x while-loop