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

Even better would be to only check each once and buffer the decision:

    valid = True
    if not API_KEY:
        print("Missing YOUTUBE_API_KEY.")
        valid = False
    if not CHANNEL_ID:
        print("Missing YOUTUBE_CHANNEL_ID.")
        valid = False
    if not valid:
        exit(1)
This way you only check each value once (because your logic might be more complicated than just checking it's not set, maybe it can be wrongly formatted) and you still get to do whatever logic you want. It also removed the combinatorial problems.

This is a pretty general principle of separating decision from action.



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

Search: