First time here? Check out the FAQ!

Revision history  [back]

ImportError: cannot import name 'Tab' from 'bar_tab'

I'm learning python. Trying to do a simple tutorial from youtube. Here is the code:

class Tab:

menu = {
    'wine': 5,
    'beer': 3,
    'soft_drink': 2,
    'chicken': 10,
    'beef': 15,
    'veggie':12,
    'dessert': 6
}

def __init__(self): 
    self.total = 0
    self.items = []

def add(self, item):
    self.items.append(item)
    self.total += self.menu[item] 

def print_bill(self, tax, service):
    tax = (tax/100)*self.total
    service = (service/100)*self.total 
    total = self.total + tax + service

    for item in self.items: 
        print(f'{item} ${self.menu[item]}')

    print(f'{"Total"} ${total:.2f}')

and using 'Cmder' from the website cmder.net, I'm writing this and getting this error:

'>>>from bar_tab import tab

Traceback (most recent call last): File "", line 1, in ImportError: cannot import name 'tab' from 'bar_tab ' (C:\Users...\bar_tab.py)

I don't understand what I'm doing wrong. Just trying to import this class from module. Can someone please help?