파이썬 multiprocessing
라이브러리를 사용하여 파일을 읽으려고하지만 원하는 결과를 얻지 못했습니다.Python 다중 처리 라이브러리를 사용하는 이상한 동작
TypeError: int() argument must be a string or a number, not 'list'
0
20050
나는 다음과 같은 문제가 있습니다 :
나는 이유를 이해하지 않습니다 여기에
내가받을 출력을 간다 : 여기 내가 사용하고 코드를 간다 위의 코드에서 길이가import multiprocessing as mp import itertools partitioned = {} partitioned['0-20'] = [] partitioned['20-40'] = [] partitioned['40-60'] = [] partitioned['60+'] = [] output = [] def map_func1(f): # for line in f: gen = f[14:15] #15 1=male 2=female age = f[17:19] #18-19 htin = f[1947:1950] #1948-1950 tall in inches, self reported !888! !999! wtlbs = f[1950:1953] #1951-1953 wt in lbs, self reported !888! !999! ovwt = f[1963:1964] #1964 consider myself overweight 1,under 2,over 3, !8!, !9! chwt = f[1964:1965] #1965 change weight or stay same 1=more, 2=less, 3=same, !8!, !9! output.append([gen, age, htin, wtlbs, ovwt, chwt]) return output def partitioner(m): for element in m: if int(element[1]) < 20: output['0-20'].append(element) elif int(element[1]) < 40: output['20-40'].append(element) elif int(element[1]) < 60: output['40-60'].append(element) else: output['60+'].append(element) return partitioned if __name__ == "__main__": pool = mp.Pool(processes=3) f = open('adult.dat') m = pool.map(map_func1, f) print len(output) print len(m) p = partitioner(m) print p
output
은 0이고 변수의 길이는m
입니다. 내게 따르면output
과m
, shou 길이는 20050입니다.이 경우
TypeError()
이 필요한 이유는 무엇입니까? 인수가partitioner
함수의 목록이 아닌 이유는 무엇입니까?디버그 창에서 변수
m
의 내용을 보려고하면 내 시스템이 거의 엉망입니다. (우분투 13.10을 사용하고 Pycharm 3.1을 실행 중입니다!) 내가 보려고하는 목록의 내용이 엄청나게 거대하면이 경우를 이해할 수 있습니다.이 경우에는 그렇지 않습니다. 이 목록은 20050 개의 목록으로 구성되며 각 목록에는 6 개의 요소가 있습니다.
이와 관련하여 도움을 주시면 감사하겠습니다.
답장을 보내 주셔서 감사합니다. 나는 그 문제를 알아 냈다. 내 map_func1은 "return [gen, age, htin, wtlbs, ovwt, chwt]"을 반환해야합니다. – Patthebug