> Date: Wed, 11 Sep 2013 18:10:18 +0530
> From: zubair alam <zubair.alam....@gmail.com>
> To: tutor <tutor@python.org>
> Subject: [Tutor] class data member and objects of class in python
> Message-ID:
>         <cagqec75oz8g8d2ibbwicdfdgqdb65sytdxkqfwvj8c2bp1o...@mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> 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

Integers different from zero are considered to be True. So what you're
basically doing is:
      >>> pizza_stock=10
      >>> while not pizza_stock:0 ## not True == False

so the loop never runs, not even once. Python reports an error because
of that. Similar reports occur if you have variables that are not used
but those are Warnings and not actual Error events.

Regards,
Dino
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to