Skip to content

Day3 orm.py Undefined variable 'StandardError' #54

Description

@pretendhigh

python 版本 Python 3.7.3
vscode 中显示 orm.py 报错: Undefined variable 'StandardError'
class ModelMetaclass(type):

def __new__(cls, name, bases, attrs):
    if name=='Model':
        return type.__new__(cls, name, bases, attrs)
    tableName = attrs.get('__table__', None) or name
    logging.info('found model: %s (table: %s)' % (name, tableName))
    mappings = dict()
    fields = []
    primaryKey = None
    for k, v in attrs.items():
        if isinstance(v, Field):
            logging.info('  found mapping: %s ==> %s' % (k, v))
            mappings[k] = v
            if v.primary_key:
                # 找到主键:
                if primaryKey:
                    raise StandardError('Duplicate primary key for field: %s' % k)

stackoverflow 中有个回答, "exception StandardError which was removed in Python 3.",是这样的吗?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions