943,965 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 474
  • Python RSS
Nov 4th, 2009
0

Array Index Issue

Expand Post »
Hi, Below is my output:



FF 0 CMA: 0 IPMI port
DE 15E0 TTA: 1 Generic Com port
DD 15D0 TTB: 2 Generic Com port
DC 15C0 SEA: 3 ACPI System Event
FF 0 1 MFPCI
DB 15B0 DQA: 2 CMD 649 IDE/ATA Controller
DA 15A0 EIA: 3 Intel 82557 LOM (Fast Ethernet)
D9 1590 OHA: 1 NEC OHCI USB Controller
D8 1580 OHB: 1 NEC OHCI USB Controller
D7 1570 EHA: 1 NEC EHCI USB Controller
FF 0 1 MFPCI
D6 1560 EWA: 2 BCM5701 LOM (Gigabit Ethernet)
D5 1550 PKA: 1 LSI Logic 1030 U320
D4 1540 PKB: 1 LSI Logic 1030 U320
D3 1530 PKC: 4 Smart Array 6400 series
D2 1520 PKD: 5 Smart Array 6400 series
FF 0 1 MFPCI
D1 1510 GHA: 2 ATI Radeon 7000
DF 15F0 1 1291103C.1290103C (<...<...)
DF 15F0 SRA: 1 Console Serial Line Driver

From this output I want get only 0,1,2,3,1,2,3,1,1,1,1,2,1,1,4,5,1,2,1,1 only when I am printing 3 array index then some cases I am getting MFPCI and 1291103C.1290103C. Please let me know how can I get this value??????
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krishna_sicsr is offline Offline
9 posts
since Oct 2009
Nov 4th, 2009
0
Re: Array Index Issue
The problem is that not all the data has the same format and the numbers you are looking for are in different "array" positions for some lines if you split those lines based on whitespace. For example:
DE 15E0 TTA: 1 Generic Com port => Number 1 is at offset 3
FF 0 1 MFPCI => Number 1 is at offset 2

Note that when the number you want is at offset 3, then the data at offset 2 is a non-numeric value ending with ":"

You could take advantage of this by:
For each line, split based on whitespace and examine the data at offset 2. If it does not end with a ':' then you can use this as your value otherwise take the data at offset 3.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
stephendoyle75 is offline Offline
8 posts
since Dec 2008
Nov 4th, 2009
0
Re: Array Index Issue
Hi, Thanks for ur reply but I tried everything and not getting the desired output. Even I am new to Python also so I don't know how to proceed thru ur logic. It would be great if u can send me some working code. Thanks Krishna_sicsr


The problem is that not all the data has the same format and the numbers you are looking for are in different "array" positions for some lines if you split those lines based on whitespace. For example:
DE 15E0 TTA: 1 Generic Com port => Number 1 is at offset 3
FF 0 1 MFPCI => Number 1 is at offset 2

Note that when the number you want is at offset 3, then the data at offset 2 is a non-numeric value ending with ":"

You could take advantage of this by:
For each line, split based on whitespace and examine the data at offset 2. If it does not end with a ':' then you can use this as your value otherwise take the data at offset 3.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krishna_sicsr is offline Offline
9 posts
since Oct 2009
Nov 4th, 2009
0
Re: Array Index Issue
Here you go, let me know if you need any more help. Note that I'm assuming that the data has been read into an array called lines with each line of text as a separate array entry. The code below gives you the desired numbers.

Python Syntax (Toggle Plain Text)
  1. for line in lines:
  2. parts = line.split()
  3. if parts[2][-1] == ':':
  4. print parts[3]
  5. else:
  6. print parts[2]
Reputation Points: 10
Solved Threads: 3
Newbie Poster
stephendoyle75 is offline Offline
8 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Help with string formatting
Next Thread in Python Forum Timeline: Back with more dumb questions!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC