标题写不下了,数据类型报错TypeError: can only concatenate tuple (not "str") to tuple
运行的时候一直报错,我不知道问题出在了哪里,可能是input_type的问题。我也不知道应该怎么解决,有人可以帮我看看吗?截取的这段代码的最后一行是出现错误的那行。用的好像是python3.8
(不知道我截的这段能看出问题吗,如果还需要看更多我再发文件或者截取更多)
# determine which array(s) to extract from npz files
if input_type == 'ensemble_full':
npfile_to_extract = ('xa_ens',)
elif input_type == 'ensemble_subsample':
npfile_to_extract = ('xa_subsample',)
elif input_type == ('ensemble_mean', 'ensemble_variance'):
npfile_to_extract = ('xam', 'xav')
elif input_type == 'ensemble_mean':
npfile_to_extract = ('xam',)
else:
print('ERROR: Non-valid option specified for input data type: %s' %input_type)
raise SystemExit(1)
# look for files corresponding to desired input_type
#listdirfiles = glob.glob(workdir+'/'+input_type+'_*')
listdirfiles = glob.glob(workdir+'/ensemble_*')
# including gmt_ensemble
listdirfiles.extend(glob.glob(workdir+'/gmt_ensemble.npz'))
# strip directory name, keep file name only
listfiles = [item.split('/')[-1] for item in listdirfiles]
# strip everything but variable name
listvars = [(item.replace(input_type+'_','')).replace('.npz','') for item in listfiles]
python里面,字符串不要用逗号结尾,你用逗号结尾的,就会从字符串变成元组,也不要加括号,如果你加了括号也会被认为是元组。所以如果你能确定是字符串的话,把括号和逗号去掉试试
npfile_to_extract = ('xa_ens',)
print(type(npfile_to_extract))
## output:
<class 'tuple'>
您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632