Bug记录——sequence item 0: expected str instance, int found

问题描述

制作等比数列的时候,输出时发现了该报错:sequence item 0: expected str instance, int found

a, b, c = 1, 3, 5
ls = []
for i in range(c):
    if i == 0:
        ls.append(a)
    else:
        ls.append(a*(b**i))
print(",".join(ls))

错误:

sequence item 0: expected str instance, int found

原因分析:

错误意思:列表中含有数字,不能直接转化成字符串

原因是 .join()方法只能对字符串进行添加操作,所以报错啦!


解决方案:

查了一下资料,提供的解决方案有点麻烦,如下:

a, b, c = 1, 3, 7
ls = []
for i in range(c):
    ls.append(a*(b**i))
print(",".join('%s' %id for id in ls))

用的是列表推导式对ls列表遍历,将其转换为字符串。但是我觉得可以在追加元素至列表时将其转换为字符串,如下:

a, b, c = 1, 3, 7
ls = []
for i in range(c):
    ls.append(str(a*(b**i)))
print(",".join(ls))
C:\Users\云实>python D:/Python39/Scripts/gdal2tiles.py -z 1-18 "D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/NDVIresult_DJI_style004.tif" D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles --xyz --processes 4 --verbose Options: {'profile': 'mercator', 'resampling': 'average', 's_srs': None, 'zoom': [1, 18], 'resume': False, 'srcnodata': None, 'tmscompatible': None, 'xyz': True, 'verbose': True, 'exclude_transparent': None, 'quiet': None, 'nb_processes': 4, 'mpi': None, 'tilesize': 256, 'tiledriver': 'PNG', 'kml': None, 'url': '', 'webviewer': 'all', 'title': 'NDVIresult_DJI_style004.tif', 'copyright': '', 'googlekey': 'INSERT_YOUR_KEY_HERE', 'bingkey': 'INSERT_YOUR_KEY_HERE', 'mapml_template': None, 'webp_quality': 75, 'webp_lossless': None, 'processes': 1} Input: D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/NDVIresult_DJI_style004.tif Output: D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles Cache: 3262 MB Begin tiles details calc Input file: (10686P x 8360L - 3 bands) NODATA: [] Preprocessed file:(10686P x 8360L - 3 bands) Modified -dstalpha warping result saved into 'tiles1.vrt' Projected file: tiles.vrt (10739P x 8480L - 4 bands) Bounds (output srs): 11578053.166325, 3563153.151313, 11578302.653489, 3563350.157659 Bounds (latlong): (30.462605551329265, 104.00742119658143), (30.46413098324938, 104.00966237790443) MinZoomLevel: 1 MaxZoomLevel: 18 (0.597164) Generating Base Tiles: Tiles generated from the max zoom level: ---------------------------------------- dataBandsCount: 3 tilebands: 4 1 / 9, D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles\18\206807\107762.png Native Extent (querysize 6580): (0, 0, 705, 378), (5875, 6202, 705, 378) 2 / 9, D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles\18\206808\107762.png Native Extent (querysize 6580): (705, 0, 6580, 378), (0, 6202, 6580, 378) 3 / 9, D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles\18\206809\107762.png Native Extent (querysize 3454): (7285, 0, 3454, 378), (0, 6202, 3454, 378) 4 / 9, D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles\18\206807\107763.png Native Extent (querysize 6580): (0, 377, 705, 6580), (5875, 0, 705, 6580) 5 / 9, D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles\18\206808\107763.png Native Extent (querysize 6580): (705, 377, 6580, 6580), (0, 0, 6580, 6580) 6 / 9, D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles\18\206809\107763.png Native Extent (querysize 3454): (7285, 377, 3454, 6580), (0, 0, 3454, 6580) 7 / 9, D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles\18\206807\107764.png Native Extent (querysize 6580): (0, 6957, 705, 1523), (5875, 0, 705, 1523) 8 / 9, D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles\18\206808\107764.png Native Extent (querysize 6580): (705, 6957, 6580, 1523), (0, 0, 6580, 1523) 9 / 9, D:/实时建模/实时建模V3/任务/建模826/2cm切图结果912/tiles\18\206809\107764.png Native Extent (querysize 3454): (7285, 6957, 3454, 1523), (0, 0, 3454, 1523) Tiles details calc complete. D:\Python39\lib\site-packages\osgeo\osr.py:410: FutureWarning: Neither osr.UseExceptions() nor osr.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default. warnings.warn( D:\Python39\lib\site-packages\osgeo\osr.py:410: FutureWarning: Neither osr.UseExceptions() nor osr.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default. warnings.warn( D:\Python39\lib\site-packages\osgeo\osr.py:410: FutureWarning: Neither osr.UseExceptions() nor osr.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default. warnings.warn( D:\Python39\lib\site-packages\osgeo\osr.py:410: FutureWarning: Neither osr.UseExceptions() nor osr.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default. warnings.warn( Generating Overview Tiles: multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "D:\Python39\lib\multiprocessing\pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "D:\Python39\lib\site-packages\osgeo_utils\gdal2tiles.py", line 1576, in create_overview_tile logger.debug(f"\tbuild from zoom {base_tz}, tiles: %s" % ",".join(base_tiles)) TypeError: sequence item 0: expected str instance, tuple found """ The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\Python39\Scripts\gdal2tiles.py", line 17, in <module> sys.exit(main(sys.argv, called_from_main=True)) File "D:\Python39\lib\site-packages\osgeo_utils\gdal2tiles.py", line 4528, in main return submain(argv, called_from_main=called_from_main) File "D:\Python39\lib\site-packages\osgeo_utils\gdal2tiles.py", line 4558, in submain multi_threaded_tiling(input_file, output_folder, options, pool) File "D:\Python39\lib\site-packages\osgeo_utils\gdal2tiles.py", line 4459, in multi_threaded_tiling for _ in pool.imap_unordered( File "D:\Python39\lib\multiprocessing\pool.py", line 870, in next raise value TypeError: sequence item 0: expected str instance, tuple found C:\Users\云实>
最新发布
09-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bio大恐龙

您的打赏是我前进的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值