| | |
Array Index Issue
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 9
Reputation:
Solved Threads: 0
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??????
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??????
•
•
Join Date: Dec 2008
Posts: 8
Reputation:
Solved Threads: 3
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.
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.
•
•
Join Date: Oct 2009
Posts: 9
Reputation:
Solved Threads: 0
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
•
•
•
•
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.
•
•
Join Date: Dec 2008
Posts: 8
Reputation:
Solved Threads: 3
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.
Python Syntax (Toggle Plain Text)
for line in lines: parts = line.split() if parts[2][-1] == ':': print parts[3] else: print parts[2]
![]() |
Similar Threads
- index arrays (C#)
- array index and returning (Java)
- Find void array index from pointer (C)
- Print the parallel array index with the largest value? (C++)
- Array Index Problem in Quick Sort (C#)
- Using a variable as an array's index? (C)
Other Threads in the Python Forum
- Previous Thread: Help with string formatting
- Next Thread: Back with more dumb questions!
| Thread Tools | Search this Thread |
accessdenied advanced aliased argv beginner bits calling casino change command convert count csv cturtle cursor def dictionary digital dynamic dynamically enter event examples external file float format frange function google gui hints homework i/o iframe import info input jaunty java keyboard lapse line linux list lists loop microphone mouse multiple newb number numbers obexftp output parameters parsing path port prime programming projects py py2exe pygame pygtk pyopengl python random recursion return scrolledtext signal skinning sprite stderr string strings subprocess table tennis terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 variable voip web-scrape whileloop windows wxpython





