我正在使用Python中的cdflib库编写一个程序,以使用以下主循环将多个CDF文件合并在一起:
for cdf_file_input in os.listdir(input_folder):
#open CDF in new temp variable
cdf_file_input = input_folder + cdf_file_input
cdf_file = cdfread.CDF(cdf_file_input)
#instantiate temp variables for zVariables
info = cdf_file.cdf_info()
zvars = info['zVariables']
#loop through zVariables and write their information, attributes and data
for x in range (0, len(zvars)):
varinfo = cdf_file.varinq(zvars[x])
varatts = cdf_file.varattsget(zvars[x])
variable = cdf_file.varget(zvars[x])
#we only add variable attributes on the first loop, otherwise only variable data is added
if count == 1:
merged_cdf.write_var(varinfo, var_attrs=varatts, var_data=variable)
else:
merged_cdf.write_var(varinfo, var_data=variable)
#iterate count number to track merge progress
count = count + 1
第一个文件合并没有问题,但是当我进入第二个文件时,出现以下错误:
文件“ C:\ Users \ Brad \ Desktop \ CDF_Merge.py”,第45行,在 merged_cdf.write_var(varinfo,var_data = variable)文件“ C:\ Users \ Brad \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-package s \ cdflib \ cdfwrite.py“,行765,在write_var中 引发ValueError('{}已经存在'.format(name))ValueError:时间戳已经存在
为write_var中的第一个参数使用空白字典不起作用,因为它们不被视为有效输入。除了重写cdflib源代码外,有人对我可以如何摆脱ValueError提出任何建议吗?