piglei / one-python-craftsman

来自一位 Pythonista 的编程经验分享,内容涵盖编码技巧、最佳实践与思维模式等方面。

Home Page:https://www.piglei.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

err_msg未定义?

zbx91 opened this issue · comments

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')

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

已修复