Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Is this a correct way to generate an exception when getting a wrong parameter Date: Wed, 12 Aug 2015 11:06:03 +0200 Organization: Decebal Computing Lines: 28 Message-ID: <87h9o46flw.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="528adfd6ad074c92fdc6a7f8fb9e23d8"; logging-data="12714"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XkGdeGsNeFAz6YtB2Wgt/IiQo3RriZeM=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:8HRGnfI+J3t3QRr3zdY67Gfksr8= sha1:fqNYZOVc0j9e/s5qffHTr6fWVeQ= Xref: csiph.com comp.lang.python:95275 I have: ======================================================================== accepted_params = { 'pcpu', 'rss', 'size', 'time', 'vsize', } ======================================================================== Later I use: ======================================================================== if (to_check != 'all') and not(to_check in accepted_params): raise Exception('Used illegal parameter: {0}.\n' 'Accepted ones: {1}' .format(to_check, sorted(accepted_params))) ======================================================================== When using 'all' I want to do the work for all accepted parameters. ;-) Is this a correct way to do this, or is there a better way? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof