Singleton python generator? Or, pickle a python generator?

前端 未结 6 1296
心在旅途
心在旅途 2021-01-03 06:58

I am using the following code, with nested generators, to iterate over a text document and return training examples using get_train_minibatch(). I would like to

6条回答
  •  迷失自我
    2021-01-03 07:36

    1. Convert the generator to a class in which the generator code is the __iter__ method
    2. Add __getstate__ and __setstate__ methods to the class, to handling pickling. Remember that you can’t pickle file objects. So __setstate__ will have to re-open files, as necessary.

    I describe this method in more depth, with sample code, here.

提交回复
热议问题