From a79491d1d37da1bd0623fe0f31a0effbc5076495 Mon Sep 17 00:00:00 2001 From: SMWARREN Date: Fri, 20 Feb 2015 16:34:31 -0500 Subject: [PATCH] Update Factory.py for Python 3.4.1 "The print statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old print statement (PEP 3105)" --- factory.py | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/factory.py b/factory.py index 4226d34..3dbd617 100644 --- a/factory.py +++ b/factory.py @@ -29,42 +29,5 @@ def create_pizza(pizza_type): if __name__ == '__main__': for pizza_type in ('HamMushroom', 'Deluxe', 'Hawaiian'): - print 'Price of {0} is {1}'.format(pizza_type, PizzaFactory.create_pizza(pizza_type).get_price()) + print('Price of {0} is {1}'.format(pizza_type, PizzaFactory.create_pizza(pizza_type).get_price()) - -# ------------------- Second example ----------------- - - -class JapaneseGetter: - """A simple localizer a la gettext""" - - def __init__(self): - self.trans = dict(dog="犬", cat="猫") - - def get(self, msgid): - """We'll punt if we don't have a translation""" - - try: - return unicode(self.trans[msgid], "utf-8") - except KeyError: - return unicode(msgid) - -class EnglishGetter: - """Simply echoes the msg ids""" - def get(self, msgid): - return unicode(msgid) - -def get_localizer(language="English"): - """The factory method""" - - languages = dict(English=EnglishGetter, - Japanese=JapaneseGetter) - - return languages[language]() - -# Create our localizers -e, j = get_localizer("English"), get_localizer("Japanese") - -# Localize some text -for msgid in "dog parrot cat".split(): - print e.get(msgid), j.get(msgid)