簡體   English   中英

在文件字符串中使用元組作為文件名

[英]Using a tuple in a file string for file names

我目前正在編寫一個forloop,它將運行一個函數,每次基於一個元組迭代地更改某個參數,然后保存輸出。 我希望輸出的文件名與為該迭代運行的變量匹配。 這是我的代碼和錯誤:

#define tuple
range_length = (50, 75)

for i in range_length:
    evs.set_module('A2_ra_Ind_krig_3d', 'Krig Settings',  'Range': i})
    evs.set_module('A2_ra_Ind_krig_3d', 'Properties', 'Execute', True)
#Where error is
    file_string = '\\\\C:\\A2_Radium_Range_{0:.0f}'.format(range_length)
    evs.set_module('write evs field', 'Properties', 'Filename', file_string)

運行時出錯:

TypeError: unsupported format string passed to tuple.__format__

請注意,我簡化了一些代碼以專注於與文件字符串相關的錯誤。 在那之前一切正常。 對此的任何幫助將不勝感激,謝謝

您要傳遞的實際上是變量i而不是range_length 因此,該行應該是

file_string = '\\\\C:\\A2_Radium_Range_{0:.0f}'.format(i)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM