Array Index Issue

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2009
Posts: 9
Reputation: krishna_sicsr is an unknown quantity at this point 
Solved Threads: 0
krishna_sicsr krishna_sicsr is offline Offline
Newbie Poster

Array Index Issue

 
0
  #1
30 Days Ago
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??????
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: stephendoyle75 is an unknown quantity at this point 
Solved Threads: 3
stephendoyle75 stephendoyle75 is offline Offline
Newbie Poster
 
0
  #2
30 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 9
Reputation: krishna_sicsr is an unknown quantity at this point 
Solved Threads: 0
krishna_sicsr krishna_sicsr is offline Offline
Newbie Poster
 
0
  #3
30 Days Ago
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


Originally Posted by stephendoyle75 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: stephendoyle75 is an unknown quantity at this point 
Solved Threads: 3
stephendoyle75 stephendoyle75 is offline Offline
Newbie Poster
 
0
  #4
30 Days Ago
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.

  1. for line in lines:
  2. parts = line.split()
  3. if parts[2][-1] == ':':
  4. print parts[3]
  5. else:
  6. print parts[2]
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC