Linux script to get most expensive processes

Cecil Westerhof Cecil at decebal.nl
Wed Aug 5 01:14:36 CEST 2015


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


More information about the Python-list mailing list