小白教程

 找回密码
 立即注册
查看: 6330|回复: 0

如何在类中创建生成器

[复制链接]

1

主题

1

帖子

3

积分

新手上路

Rank: 1

积分
3
发表于 2021-5-21 04:27:58 | 显示全部楼层 |阅读模式
我有一个类,在这个类内,我有这个功能:
  1. def ff(self, timelimit):
  2.      
  3.      while self.lasttime < timelimit :
  4.          ... do your stuff                  
  5.      self.otherpart.messagelist.append((self.lasttime + self.delaytime, self.fakeid))
  6.      return None
复制代码
我也有一个外部功能,这是使用我的ff fucntion:
  1. def Simulatetilltime(A, timelimit):
  2.      B=A.otherport
  3.      Alist = []
  4.      Blist = []
  5.      A.lastt
  6.       
  7.      while A.lasttime < timelimit :
  8.        try:
  9.           if A.lasttime <= B.lasttime :
  10.               x=A.ff( B.lasttime+A.delaytime)
  11.               if x!=None: Alist.append(x)
  12.           else :
  13.               print("Here we are****************************************************")
  14.               x=B.ff( A.lasttime+B.delaytime)
  15.               if x!=None: Blist.append(x)
  16.        except StopIteration: break      
  17.      return Alist, Blist
复制代码
我想在类内创建生成器,而不是仅使用函数。我该怎么做?

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|小白教程 ( 粤ICP备20019910号 )

GMT+8, 2024-9-20 14:35 , Processed in 0.058478 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc. Template By 【未来科技】【 www.wekei.cn 】

快速回复 返回顶部 返回列表