Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 Lists in my code.
data list is having len = 11
new_list is having len = 23

I have to search if a string from data list and check if it exists in new_list.
I can see that my target_data gets filled with data,but when i go to print it, I get an error..


My data list contents as below:
RegInputOutput-ML                         Warning     /sitework/soc/users/law/yeppy2/yeppy2chewy/yeppy2chewy_4ports/yeppy2/Spy_test_prj/mem/project_1/project_1.srcs/sources_1/ip/blk_mem_gen_0/synth/blk_mem_gen_0.vhd 315  10   Port 'clka' is not registered [Hierarchy: 'block_ram_top.blk_mem_inst_0']
RegInputOutput-ML                         Warning     /sitework/soc/users/law/yeppy2/yeppy2chewy/yeppy2chewy_4ports/yeppy2/Spy_test_prj/mem/project_1/project_1.srcs/sources_1/ip/blk_mem_gen_0/synth/blk_mem_gen_0.vhd 315  10   Port 'clka' is not registered [Hierarchy: 'block_ram_top.blk_mem_inst_1']
RegInputOutput-ML                         Warning     /sitework/soc/users/law/yeppy2/yeppy2chewy/yeppy2chewy_4ports/yeppy2/Spy_test_prj/mem/project_1/project_1.srcs/sources_1/ip/blk_mem_gen_0/synth/blk_mem_gen_0.vhd 317  10   Port 'ena' is not registered [Hierarchy: 'block_ram_top.latch']
RegInputOutput-ML                         Warning     /sitework/soc/users/law/yeppy2/yeppy2chewy/yeppy2chewy_4ports/yeppy2/Spy_test_prj/mem/project_1/project_1.srcs/sources_1/ip/blk_mem_gen_0/synth/blk_mem_gen_0.vhd 317  10   Port 'ena' is not registered [Hierarchy: 'block_ram_top.ff1']
RegInputOutput-ML                         Warning     /sitework/soc/users/law/yeppy2/yeppy2chewy/yeppy2chewy_4ports/yeppy2/Spy_test_prj/mem/project_1/project_1.srcs/sources_1/ip/blk_mem_gen_0/synth/blk_mem_gen_0.vhd 319  10   Port 'wen' is not registered [Hierarchy: 'block_ram_top']


new_list contents
| block_ram_top | (top) | 23 | 23 | 0 | 0 | 138 | 0 | 2 | 0 | 4 |
| (block_ram_top) | (top) | 7 | 7 | 0 | 0 | 9 | 0 | 0 | 0 | 0 |
| blk_mem_inst_0 | blk_mem_gen_0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| (blk_mem_inst_0) | blk_mem_gen_0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |


The variable that i extract from the new_list in my code:
inst_blk_mem_gen']
gnbram.gnativebmg.native_blk_mem_gen']
valid.cstr']
ramloop[0].ram.r']
prim_noinit.ram']
blk_mem_inst_1']
U0']
block_ram_top']
blk_mem_inst_0']
complex_multiplier_inst']

Expected target_data list:
This should have all the data list items having the variable that i extract from the new_list items:
RegInputOutput-ML Warning /sitework/soc/users/law/yeppy2/yeppy2chewy/yeppy2chewy_4ports/yeppy2/Spy_test_prj/mem/project_1/project_1.srcs/sources_1/ip/blk_mem_gen_0/synth/blk_mem_gen_0.vhd 315 10 Port 'clka' is not registered [Hierarchy: 'block_ram_top.blk_mem_inst_0']
RegInputOutput-ML Warning /sitework/soc/users/law/yeppy2/yeppy2chewy/yeppy2chewy_4ports/yeppy2/Spy_test_prj/mem/project_1/project_1.srcs/sources_1/ip/blk_mem_gen_0/synth/blk_mem_gen_0.vhd 315 10 Port 'clka' is not registered [Hierarchy: 'block_ram_top.blk_mem_inst_1']
RegInputOutput-ML Warning /sitework/soc/users/law/yeppy2/yeppy2chewy/yeppy2chewy_4ports/yeppy2/Spy_test_prj/mem/project_1/project_1.srcs/sources_1/ip/blk_mem_gen_0/synth/blk_mem_gen_0.vhd 319 10 Port 'wen' is not registered [Hierarchy: 'block_ram_top']


Please help me get rid of this error..I am new to python hence finding it difficult.

What I have tried:

My code:
print len(new_list)
print len(data)
      
for i in range(len(new_list)):
    parts = (new_list[i].split('|'))
    #print parts
    if (int(parts[8]) >= 1 or int(parts[9])  >= 1 or int(parts[11])  >= 1 ):
        variable = parts[1]
        variable = variable.strip()
        variable = variable + "']"
        #print variable
        for d in data:
            if variable in d:
                target_data.append(d) 
                print "ok"
            else:
                NODATA = 1
    else:
        NODATA = 1
print target_data


Error from the command line:
23
11
ok
ok
ok
ok
ok
ok
ok
ok
ok
ok
ok
list index out of range
Posted
Comments
Richard Deeming 29-Sep-20 6:22am    
At a guess, one of the strings in new_list doesn't contain at least 12 columns separated by | characters, so one of your parts[...] accesses is failing.

Try putting print len(parts) inside the loop, where you've currently got the commented-out print parts line.
Richard MacCutchan 29-Sep-20 8:12am    
Please show all the data that you are trying to process.
Member 11362771 30-Sep-20 6:49am    
I have added the lists data that i use in my question itself
Richard MacCutchan 30-Sep-20 7:02am    
At the beginning of your program you print the length of new_list, which is 23. That does not match the data you have shown.
Member 11362771 30-Sep-20 6:41am    
@Richard Deeming...You are absolutely right...One of the item in the new_list had lesser length..hence it could not pass the if statement...Thank you for your observation..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900