[Tutor] class data member and objects of class in python

zubair alam zubair.alam.jmi at gmail.com
Wed Sep 11 14:40:18 CEST 2013


i am learning how a __class__ data member behaves in python as compared to
static data member in java, but following code is throwing error


class PizzaShop():
    pizza_stock = 10
    def get_pizza(self):
        while not PizzaShop.pizza_stock:
            PizzaShop.pizza_stock -= 1
            yield "take yours pizza order, total pizzas left
{}".format(PizzaShop.pizza_stock)

mypizza_shop = PizzaShop()
pizza_order = mypizza_shop.get_pizza() # iterator is obtained
print "a pizza pls!! {}:".format(pizza_order.next())
print "a pizza pls!! {}:".format(pizza_order.next())

output:
Traceback (most recent call last):
  File "/home/scott/pythonfiles/core_python/pizza.py", line 10, in <module>
    print "a pizza pls!! {}:".format(pizza_order.next())
StopIteration


don't know where i am doing mistake....any help will be appreciated... i
have other questions on based on this class
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130911/4e1bac27/attachment.html>


More information about the Tutor mailing list