Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Re: Linux script to get most expensive processes Date: Wed, 05 Aug 2015 01:14:36 +0200 Organization: Decebal Computing Lines: 35 Message-ID: <87k2tahcir.fsf@Equus.decebal.nl> References: <87twsehkmk.fsf@Equus.decebal.nl> <87pp32hhbr.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="528adfd6ad074c92fdc6a7f8fb9e23d8"; logging-data="4877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/O1P5jRK7H6RMZ3LBg3bjQRpHsUY/eQ50=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:ME0fZqw2mkQbbR2TzXTARBWVMd4= sha1:WkymFUSzcMjs6NKePnwbDC+Nx9Y= X-Homepage: http://www.decebal.nl/ Xref: csiph.com comp.lang.python:94982 On Wednesday 5 Aug 2015 00:00 CEST, MRAB wrote: >> I amended the code to work with linux and linux2: >> ======================================================================== >> accepted_params = { 'pcpu', 'rss', 'size', 'time', 'vsize', } >> accepted_platforms = { 'linux', 'linux2', } current_platform = >> sys.platform max_line_length = 200 no_of_lines = 8 # One extra for >> the heading >> >> is_good_platform = False for platform in accepted_platforms: if >> platform == current_platform: is_good_platform = True break if not >> is_good_platform: raise Exception('Got an incompatiple platform: >> {0}'. format(current_platform)) >> ======================================================================== >> > Doesn't that 'for' loop do the same as: > > is_good_platform = current_platform in accepted_platforms You are right. Not very smart. Especially because I use the ‘in’ a little later. It now is: ======================================================================== if not current_platform in accepted_platforms: raise Exception('Got an incompatiple platform: {0}'. format(current_platform)) ======================================================================== And I do not need is_good_platform anymore. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof