piglei/one-python-craftsman

err_msg未定义?

zbx91 opened this issue · 2 comments

zbx91 commented

class CreateItemError(Exception):
"""创建 Item 失败时抛出的异常"""

def create_item(name):
"""创建一个新的 Item

:raises: 当无法创建时抛出 CreateItemError
"""
if len(name) > MAX_LENGTH_OF_NAME:
    raise CreateItemError('name of item is too long')
if len(CURRENT_ITEMS) > MAX_ITEMS_QUOTA:
    raise CreateItemError('items is full')
return Item(name=name)

def create_for_input():
name = input()
try:
item = create_item(name)
except CreateItemError as e:
print(f'create item failed: {err_msg}') #这句是不是有bug,err_msg 无定义
else:
print(f'item<{name}> created')

应该是有点问题,我晚点会修复下。

已修复