Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Python doesn't have enumerations, per se. Here's how I'd represent that:

    if 'edit' in structure['access']:
         # can edit
    
In which case it really doesn't matter if there's junk in access. If I really felt the need to validate the structure, I could do so with:

    if not set(structure['access']).issubset(all_access_privs):
        raise ValueError('invalid access types passed in')
but more realistically, I'd rely on the ORM object to validate against the authoritative source - the database - and key off the errors there.


Python 3.4 has enums, if that's what you meant: https://docs.python.org/3/library/enum.html




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: