我试图将一些JSON对象和两个整数传递给一个池。在
for i in range(0, multiprocessing.cpu_count()-1):
fromindex = i * chunklen
toindex = (i+1) * chunklen
chunkedData.append([data['features'][fromindex:toindex], weekdaytopredict, hourtopredict])
chunkedData.append([data['features'][toindex:], weekdaytopredict, hourtopredict])
parallelstart = time.time()
result = (pool.map(parallelUpdateWithDT, chunkedData))
data
是一个带有一些多边形的geoJSON文件。我想分配这些多边形进行并行处理。我将n/cpu_count()
多边形传递给parallelUpdateWithDT
函数,该函数将进一步处理它们。我的问题是一个typeerror:即使print(chunkedData)
返回<class 'list'>
,我还是得到了以下错误:TypeError: a bytes-like object is required, not 'str'
。我在哪里搞砸了?完整堆栈跟踪:
chunkedData
示例:
[[[{'geometry': {'coordinates': [[[10.914622377957983, 45.682007076150505], [10.927456267537572, 45.68179119797432], [10.927147329501077, 45.672795442796335], [10.914315493899755, 45.67301125363092], [10.914622377957983, 45.682007076150505]]], 'type': 'Polygon'}, ///////////////////////etc, waaay too big////////////, 'id': 6574, 'properties': {'cellId': 11454}}], 3, 5]
这是怎么回事?我不明白。谢谢你的帮助!在
从您发布的代码中无法判断,但我怀疑您试图检查
str
是否是in
abytes
。例如:这意味着代码中的
^{pr2}$result
是bytes
类型。这里有两个决议。第一种方法是将'rain'
也变成bytes对象:第二种方法是将
result
转换为str
:如果您打算采用第二种方法,您应该尽早将结果转换为}之间的各种头痛。通常,如果你不知道你需要一个不同的编解码器,那么现在大多数东西都是用^{来工作的,所以你可以试试这个。。。在
str
,以避免str
与{相关问题 更多 >
编程相关推荐