How to troubleshoot an “AttributeError: __exit__” in multiproccesing in Python?

后端 未结 4 676
执笔经年
执笔经年 2020-12-13 22:41

I tried to rewrite some csv-reading code to be able to run it on multiple cores in Python 3.2.2. I tried to use the Pool object of multiprocessing, which I adap

4条回答
  •  萌比男神i
    2020-12-13 23:27

    The problem is in this line:

    with pattern.findall(row) as f:
    

    You are using the with statement. It requires an object with __enter__ and __exit__ methods. But pattern.findall returns a list, with tries to store the __exit__ method, but it can't find it, and raises an error. Just use

    f = pattern.findall(row)
    

    instead.

提交回复
热议问题