简体   繁体   中英

error "too many values to unpack" while converting generator object to list

I'm using rasterio sample module and I want to convert my output (generator) to list. I know that I can just use list() but it raises error "too many values to unpack (expected 2)". When I just use the sample module I get generator:

sample = rasterio.sample.sample_gen(raster, ['754707','4248548'])

but trying to make a list with:

sample = list(rasterio.sample.sample_gen(raster, ['754707','4248548']))

raises an error. I found.items() method but it works for dictionaries, it's not useful for generators, I'm working for the first time with a generator object and I don't get what is wrong.

Try:

sample = list(rasterio.sample.sample_gen(raster, [('754707','4248548')]))

In your example, the strings in your list are Sequence -like and iterable so when unpacking them, they get 6 values and it is expecting two values. Those strings might need be int or float , I'm not sure though

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM