python dont capitalize after apostrophe

Question

first post so go easy on me. I am trying to make it to where when I run my class the name of the restaurant comes back like a title. The problem I ran into was with joe's it comes back as Joe'S with a capital S when I use title(). When I use capitalize() Joe's comes back fine but burger king comes back as Burger king with a lower case k. I am trying to find out how to simplify this so I can have the capitalized letter of each word, without capitalizing the S after the apostrophe. The example I am working on is from Python Crash Course chapter 9. I am running Geany with python version 3.xx. Thanks for all the help.

class Restaurant():
    def __init__(self, restaurant_name, cuisine_type):
        """Initialize name and cuisine type"""
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type

    def describe_restaurant(self):
        print(self.restaurant_name.title() + " serves " + self.cuisine_type)

    def open_restaurant(self):
        print(self.restaurant_name.capitalize() + " is now open!")

restaurant = Restaurant('joe\'s', 'mexican')
burger_king = Restaurant('burger king', 'burgers')
restaurant.describe_restaurant()
restaurant.open_restaurant()
burger_king.describe_restaurant()
burger_king.open_restaurant()

Show source
| function   | class   | python   | python-3.x   | methods   2017-01-05 12:01 1 Answers

Answers to python dont capitalize after apostrophe ( 1 )

  1. 2017-01-05 12:01

    Just split and join in open_restaurant

    class Restaurant():
        def __init__(self, restaurant_name, cuisine_type):
            """Initialize name and cuisine type"""
            self.restaurant_name = restaurant_name
            self.cuisine_type = cuisine_type
    
        def describe_restaurant(self):
            print(self.restaurant_name.title() + " serves " + self.cuisine_type)
    
        def open_restaurant(self):
            Name = self.restaurant_name
            print(' '.join([x.capitalize() for x in Name.split(' ')]) + " is now open!")
    
    restaurant = Restaurant('joe\'s', 'mexican')
    burger_king = Restaurant('burger king', 'burgers')
    restaurant.describe_restaurant()
    restaurant.open_restaurant()
    burger_king.describe_restaurant()
    burger_king.open_restaurant()
    

Leave a reply to - python dont capitalize after apostrophe

◀ Go back