3 ms·
Even slightly better is to first check both if not API_KEY and not CHANNEL_ID: print("Missing both YOUTUBE_API_KEY and YOUTUBE_CHANNEL_ID.")
by cristoperb 1y ago
Even slightly better is to first check both
if not API_KEY and not CHANNEL_ID:
print("Missing both YOUTUBE_API_KEY and YOUTUBE_CHANNEL_ID.")
exit(1)
if not API_KEY:
print("Missing YOUTUBE_API_KEY.")
exit(1)
if not CHANNEL_ID:
print("Missing YOUTUBE_CHANNEL_ID.")
exit(1)
That way you don't end up fixing one just come back and be told you're also missing another requirement
- delusional 1y agoEven 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.
- pinoy420 1y ago[dead]