weixin_49304940 2021-04-07 10:58 采纳率: 100%
浏览 1626
已采纳

数据类型报错TypeError: can only concatenate tuple (not

标题写不下了,数据类型报错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]
  • 写回答

2条回答 默认 最新

  • 爱晚乏客游 2021-04-07 11:29
    关注

    python里面,字符串不要用逗号结尾,你用逗号结尾的,就会从字符串变成元组,也不要加括号,如果你加了括号也会被认为是元组。所以如果你能确定是字符串的话,把括号和逗号去掉试试

    npfile_to_extract = ('xa_ens',)
    print(type(npfile_to_extract))
    
    ## output:
    <class 'tuple'>
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)