Python iteration over non-sequence

后端 未结 4 1144
温柔的废话
温柔的废话 2021-01-04 01:16

I have this piece of code which creates a note and adds to the notebook. When I run this I get a Iteration over non-sequence error.

import datetime
class Not         


        
4条回答
  •  离开以前
    2021-01-04 02:04

    If you wanted to actually iterate Notes itself, you could also add a custom __iter__ method to it that returns the .notes property.

    class Notebook:
    
        def __iter__(self):
            return iter(self.notes)
    
        ...
    

提交回复
热议问题