Python Forum
Child Class, Loop list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Child Class, Loop list
#1
Greetings!
I've been struggling with printing my list elements, called from a method.
Have been trying to approach this from all kinds of angles, but got stuck on each attempt.
Here is my code:

class Restaurant():
    """A simple attempt to model a restaurant"""
    
    def __init__(self, restaurant_name, cuisine_type):
        """Initialize name and cuisine attributes"""
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type
        
    def describe_restaurant(self):
        """Print restaurant name and cuisine type"""
        print("Welcome to " + self.restaurant_name.title() + ".")
        print("We serve a healthy variety of dishes to suit your palette, most of our food is based on " + self.cuisine_type + ".")
    
    def open_restaurant(self):
        """Display a message that the restaurant is open"""
        print(self.restaurant_name.title() + " is open!")
        

class IceCreamStand(Restaurant):
    """Represents aspects of a restaurant, specific to an Ice-cream stand."""
    def __init__(self, flavors, restaurant_name, cuisine_type):
        """Initialize attributes to describe flavors in the Ice-cream stand"""
        super().__init__(flavors, restaurant_name, cuisine_type)
        self.flavors = ['lemon', 'malaga', 'pistacio', 'mocca']
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type
 
    #This last part seems to be the issue:
       
    def flavors(self, flav):
        for flavors in self.flavors:
            print(flavor)
        self.flav = ice_stand.flavors()
            
ice_stand = IceCreamStand(self.flav, 'ice', 'ok')
Any help is appreciated!
Reply
#2
You need to choose different names for the attribute self.flavors and the method def flavors(self) otherwise the expression self.flavors will always retrieve the attribute instead of the method. I suggest def print_flavors() as it better describes what the method actually does.
Reply
#3
That, and some other changes seemed to have fixed it, thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Child class function of Log return "None" mbilalshafiq 2 2,222 Jun-30-2020, 07:22 PM
Last Post: mbilalshafiq
  How do you compute tf-idf from a list without using the counter class syntaxkiller 8 5,219 Dec-01-2017, 05:24 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020