我有一些來自另一個 python 檔案的文本,并想將它呼叫到我正在處理的檔案中,我在其中標記了文本的每個部分doc_1, doc_2,..., doc_13。我已成功匯入該檔案,該檔案名為training.
這是代碼:
from documents import training as train # imported the file
doc_labels = []
for i in range(1, 14):
doc = f'doc_{i}'
doc_labels.append(doc)
print(doc_labels) # This prints out a list of the document names
train_docs = []
for i in range(len(doc_labels)):
doc = train.doc_labels[i] # trying to call the text from the documents
train_docs.append(doc)
這是帶有文本的檔案串列,這是培訓檔案:
doc_1 = """
text
"""
doc_2 = """
text
"""
.
.
.
doc_13 = """
text
"""
uj5u.com熱心網友回復:
您可以在檔案中添加分隔符并使用 str.split(separator)
或使用Regex101.com 計算出您想要進行的匹配。
或檢查此答案答案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/318465.html
上一篇:不同的讀寫指標
