вызываю функцию генератор и возвращается не то что надо
вот мой код
class Ad():
array_ad=[]
def get_ad(self):#показывает обьявление
txt=self.user_name+'\n'+'\n'+self.text_ad
return( txt)
@staticmethod
def next_ad():
i=0
while True:
if Ad.i<len(Ad.array_ad):
t=Ad.array_ad[Ad.i].get_ad()
Ad.i+=1
yield t
else:
yield 'end'
при запуске выдает <generator object Ad.next_ad at 0x0000022FFF556648>
Ответы (1 шт):
Автор решения: handowl
→ Ссылка
Может быть, это то, что Вам надо
class Ad():
array_ad=['text1', 'text2', 'text3']
i = 0
def __init__(self):
self.user_name = 'handowl'
self.text_ad = 'ad text'
def get_ad(self):#показывает обьявление
txt = self.user_name+'\n'+'\n'+self.text_ad
return (txt)
@staticmethod
def next_ad():
while Ad.i < len(Ad.array_ad):
t = Ad.array_ad[Ad.i]
Ad.i += 1
yield t
yield 'end'
a = Ad()
for i in a.next_ad():
print(i)