From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHDrY-0001IX-C7 for qemu-devel@nongnu.org; Thu, 07 Jan 2016 11:56:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aHDrV-0002Fm-ME for qemu-devel@nongnu.org; Thu, 07 Jan 2016 11:56:36 -0500 Received: from e06smtp14.uk.ibm.com ([195.75.94.110]:36082) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHDrV-0002Fc-Ba for qemu-devel@nongnu.org; Thu, 07 Jan 2016 11:56:33 -0500 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 Jan 2016 16:56:31 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id EBAC32190056 for ; Thu, 7 Jan 2016 16:56:17 +0000 (GMT) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u07GuSlp9175316 for ; Thu, 7 Jan 2016 16:56:28 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u07GuS5f023384 for ; Thu, 7 Jan 2016 09:56:28 -0700 References: <1449749584-23214-1-git-send-email-frankja@linux.vnet.ibm.com> <1449749584-23214-21-git-send-email-frankja@linux.vnet.ibm.com> <568E8274.7010102@redhat.com> From: Janosch Frank Message-ID: <568E98BB.1080707@linux.vnet.ibm.com> Date: Thu, 7 Jan 2016 17:56:27 +0100 MIME-Version: 1.0 In-Reply-To: <568E8274.7010102@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 20/34] scripts/kvm/kvm_stat: Cleanup cpu list retrieval List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: cornelia.huck@de.ibm.com On 01/07/2016 04:21 PM, Paolo Bonzini wrote: > > > On 10/12/2015 13:12, Janosch Frank wrote: >> + with open('/sys/devices/system/cpu/online') as cpu_list: >> + cpu_string = cpu_list.readline() >> + cpus = cpu_string.split(',') >> + >> + for cpu in cpus: >> + if '-' not in cpu: >> + cpulist.append(int(cpu)) >> + else: >> + cpu_range = cpu.split('-') >> + cpulist.extend(range(int(cpu_range[0]), >> + int(cpu_range[1]) + 1)) > > Perhaps you can move everything after readline() to a separate function? > > Paolo The string analysis to extract the cpu numbers is only needed in the get_online_cpus function where it resides, so why do you want to split this function into two? Its also only a few lines which are easy to read.