如何修复无法解压python中不可迭代的错误

问题描述 投票:0回答:1

我有以下代码:

import netCDF4
from netCDF4 import Dataset
import numpy as np
import sys
import time
import calendar
import datetime as dt
import pandas as pd
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

def print_var_recursively(grp):
    for varname in list(grp.variables.keys()):
        var=grp.variables[varname]
        dims=var.dimensions
        if not ('scanline' in dims and 'ground_pixel' in dims and 'time' in dims):
            continue
        if 'corner' in dims or varname=='time_utc':
            continue
        print(dims['time'])
        print(varname,dims)
        print(var)


def ncdump(nc_fid, verb=True):
    '''
    ncdump outputs dimensions, variables and their attribute information.
    The information is similar to that of NCAR's ncdump utility.
    ncdump requires a valid instance of Dataset.

    Parameters
    ----------
    nc_fid : netCDF4.Dataset
        A netCDF4 dateset object
    verb : Boolean
        whether or not nc_attrs, nc_dims, and nc_vars are printed

    Returns
    -------
    nc_attrs : list
        A Python list of the NetCDF file global attributes
    nc_dims : list
        A Python list of the NetCDF file dimensions
    nc_vars : list
        A Python list of the NetCDF file variables
    '''

def print_ncattr(key):
    """
    Prints the NetCDF file attributes for a given key

    Parameters
    ----------
    key : unicode
        a valid netCDF4.Dataset.variables key
    """

#=====================================================

try:
    fileList=open('fileList.txt','r')
except:
   print('Did not find a text file containing file names (perhaps name does not mathc)')
   sys.exit()
else:
    for FILE_NAME in fileList:
        FILE_NAME=FILE_NAME.strip()
        user_input=input('\nWould you like to process\n'+FILE_NAME+'\n\n(Y/N)')
        if(user_input=='N' or user_input=='n'):
            print('Skipping...')
            continue
        else:
            nc_file=Dataset(FILE_NAME,'r')
            nc_attrs,nc_dims,nc_vars=ncdump(nc_file)
            print_var_recursively(nc_file.groups['PRODUCT'])
    nc_file.close()

#=====================================================

如果我运行代码,我会收到消息:

'TypeError: cannot unpack non-iterable NoneType object'

有人可以启发我吗?

python typeerror nonetype
1个回答
0
投票

我无法发表评论,但我确定它与ncdump函数有关。它可能不会返回任何内容,因此不会返回任何内容,您正在尝试将其打开包装。

© www.soinside.com 2019 - 2024. All rights reserved.