43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import re
|
|
|
|
|
|
def read_questions_from_file(file_path):
|
|
questions = []
|
|
current_question = ""
|
|
current_number = 0
|
|
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
for line in file:
|
|
line = line.strip()
|
|
|
|
if not line: # 跳过空行
|
|
continue
|
|
|
|
if line.startswith('#'): # 跳过以#开头的行
|
|
continue
|
|
|
|
# 检查是否是新的问题编号,例如 "1."
|
|
match = re.match(r'^(\d+)\.', line)
|
|
if match:
|
|
# 如果有之前的问题,保存它
|
|
if current_question:
|
|
questions.append(current_question.strip())
|
|
|
|
# 开始新的问题
|
|
current_number = int(match.group(1))
|
|
# 提取问题内容,去掉编号和点
|
|
current_question = line.split('.', 1)[1].strip() + "\n"
|
|
else:
|
|
# 继续添加到当前问题
|
|
current_question += line + "\n"
|
|
|
|
# 添加最后一个问题(如果存在)
|
|
if current_question:
|
|
questions.append(current_question.strip())
|
|
|
|
return questions
|
|
|
|
|
|
qualification_review_file_path = 'D:\\flask_project\\flask_app\\static\\提示词\\资格评审.txt'
|
|
ques=read_questions_from_file(qualification_review_file_path)
|
|
print(ques) |