[英]Writing to file in specific format?
我有一個方法可以生成並返回一個字符串和一個字符串列表。 例子:
def func():
string_val = some code to generate string...
list_of_string = some code to generate list of string...
return string_val, list_of_string
Output:
string_val = 'some string_1'
list_of_string = ['string 1.1', 'string 1.2']
我的方法將被多個線程調用(我正在使用concurrent.futures.thread
中的ThreadPoolExecutor
)並且每個線程將生成不同的數據。
我想將此數據寫入以下格式的文件:
some string_1 <-- value returned by thread 1
some string_2 <-- value returned by thread 2
.
.
.
some string_n <-- value returned by thread n
string 1.1 <-- value returned by thread 1
string 1.2 <-- value returned by thread 1
string 2.1 <-- value returned by thread 2
string 2.2 <-- value returned by thread 2
string 2.3 <-- value returned by thread 2
.
.
.
string n.m <-- value returned by thread n
編輯:
生成並存儲在list_of_string
中的值取決於string_val
的值。
有沒有實現這一目標的最佳方法?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.