Mar-18-2019, 08:01 PM
(Mar-17-2019, 09:11 PM)rhysers Wrote: I know that use of eval() on input is just a bad ideaIn this case, because you're checking that the entire input string is within the valid list, I don't think it's that crazy here. There aren't any situations where you're running unknown code, as it needs an exact match.
That said, I think I'd still rather see a dict...
valid = {"internetGood": internetGood, 'internetOK': internetOK, 'internetBad': internetBad, 'alexaGood': alexaGood, 'alexaWarning': alexaWarning, 'alexaBad': alexaBad, 'stop': stop, 'noUpdates': noUpdates, 'secUpdates': secUpdates, 'updates': updates, 'needReboot': needReboot} # ... and then... if stringOut in valid: valid[stringOut]()...if for no other reason than it allows you to change your architecture and rewrite either end of your code, without having to rewrite both the server and the client at the same time.