Note that there are some explanatory texts on larger screens.

plurals
  1. POPython indexing into an list and getting an error I shouldn't be getting
    text
    copied!<p>I am indexing into a list like this</p> <pre><code>if first.Barcode == rcv_record[rcv_record_len-1][0]: do stuff </code></pre> <ul> <li><code>first.Barcode</code> is a string</li> <li><code>rcv_record</code> is a list that looks like this <code>[[],[],[]]</code> like so</li> <li>and <code>rcv_record_len</code> is the <code>len(rcv_record)</code></li> </ul> <p>it was working fine and now it says <code>unsupported opperand - on int and list</code> but 1 and <code>rcv_record_len</code> are both ints. Anyone have any clue?</p> <p>Edit the way I am adding to this list is by extending a tmp list and then appending to rcv_record</p> <pre><code>tmp.extend([first.Cost*first.Qty]) tmp.extend([first.Qty]) tmp.extend([first.Name]) tmp.extend([first.Units_case]) #tmp.extend([(first.Units_case)/(first.Cost)]) &lt;&lt; if this is not commented werid stuff happens import pdb; pdb.set_trace() rcv_record.append(tmp) rcv_record_len = len(rcv_record) while first != []: import pdb; pdb.set_trace() if first.Barcode == rcv_record[rcv_record_len-1][0]: </code></pre> <p>I am starting to think there is a bug or something. After uncommenting and commenting it the same error pops up on another line that has this code</p> <pre><code>if hasattr(first,'Cga_type'): </code></pre> <p>which has nothing to do with ints same error though</p> <p>Also I am using pdb and stepping through the code and am copying and pasting the offending piece and it works but as soon as I run without the debugger it breaks.</p> <p>I have edited out </p> <pre><code>tmp.extend([first.Units_case]) tmp.extend([(first.Units_case)/(first.Cost)]) </code></pre> <p>and commented out the code where this is ever used or referenced and everything works as it should. This is to prove that the issue isn't with what I currently have but is with this new snippet that for whatever reason breaks everything. After these are added I get the weird opperand int list errors. </p> <p>Here is the beast it's a wreck I know but this project just sorta fell on my lap.</p> <pre><code>if Type == 'burn rate': RcvRecords = [] RmvRecords = [] while broken_item_len &gt; 0: if broken_item[broken_item_len-1][0] == 'Chemicals': RcvRecords.extend(ChemicalRecord.objects.filter(Date__range=[From,To]).filter(Barcode=Chemicals.objects.get(id=broken_item[broken_item_len-1][1]).Barcode).filter(Action='Receiving').filter(Valid=True)) RmvRecords.extend(ChemicalRecord.objects.filter(Date__range=[From,To]).filter(Barcode=Chemicals.objects.get(id=broken_item[broken_item_len-1][1]).Barcode).filter(Action='Removing').filter(Valid=True)) if broken_item[broken_item_len-1][0] == 'Supplies': RcvRecords.extend(SupplyRecord.objects.filter(Date__range=[From,To]).filter(Barcode=Supplies.objects.get(id=broken_item[broken_item_len-1][1]).Barcode).filter(Action='Receiving').filter(Valid=True)) RmvRecords.extend(SupplyRecord.objects.filter(Date__range=[From,To]).filter(Barcode=Supplies.objects.get(id=broken_item[broken_item_len-1][1]).Barcode).filter(Action='Removing').filter(Valid=True)) if broken_item[broken_item_len-1][0] == 'Gasses': RcvRecords.extend(GasRecord.objects.filter(Date__range=[From,To]).filter(Barcode=Gasses.objects.get(id=broken_item[broken_item_len-1][1]).Barcode).filter(Action='Receiving').filter(Cga_type=Gasses.objects.get(id=broken_item[broken_item_len-1][1]).Cga_type).filter(Size=Gasses.objects.get(id=broken_item[broken_item_len-1][1]).Size).filter(Valid=True)) RmvRecords.extend(GasRecord.objects.filter(Date__range=[From,To]).filter(Barcode=Gasses.objects.get(id=broken_item[broken_item_len-1][1]).Barcode).filter(Action='Removing').filter(Cga_type=Gasses.objects.get(id=broken_item[broken_item_len-1][1]).Cga_type).filter(Size=Gasses.objects.get(id=broken_item[broken_item_len-1][1]).Size).filter(Valid=True)) broken_item_len = broken_item_len - 1 RcvRecords_len = len(RcvRecords) RmvRecords_len = len(RmvRecords) tmp_RcvRecords = RcvRecords tmp_RcvRecords_len = len(tmp_RcvRecords) tmp_RmvRecords = RmvRecords rcv_record = [] tmp = [] debugg = '' #import pdb; pdb.set_trace() while tmp_RcvRecords_len &gt; 0: if tmp_RcvRecords: first = tmp_RcvRecords.pop() tmp_RcvRecords_len = len(tmp_RcvRecords) debugg = 'pop' #import pdb; pdb.set_trace() if rcv_record == []: tmp.append(first.Barcode) debugg = 'check barcode' #import pdb; pdb.set_trace() if hasattr(first,'Cga_type'): tmp.extend(first.Cga_type) tmp.extend(first.Size) debugg = 'cga exists' #import pdb; pdb.set_trace() else: tmp.extend(['','']) tmp.extend([first.Cost*first.Qty]) tmp.extend([first.Qty]) tmp.extend([first.Name]) #tmp.extend([first.Units_case]) &lt;&lt; THIS PIECE #tmp.extend([(first.Units_case)/(first.Cost)]) &lt;&lt; THIS PIECE import pdb; pdb.set_trace() rcv_record.append(tmp) tmp = [] debugg = 'herp' else: rcv_record_len = len(rcv_record) while first != []: import pdb; pdb.set_trace() if first.Barcode == rcv_record[rcv_record_len-1][0]: import pdb; pdb.set_trace() if hasattr(first,'Cga_type'): if first.Cga_type == rcv_record[rcv_record_len-1][1]: if first.Size == rcv_record[rcv_record_len-1][2]: rcv_record[rcv_record_len-1][3] = rcv_record[rcv_record_len-1][3]+(first.Cost*first.Qty) rcv_record[rcv_record_len-1][4] = rcv_record[rcv_record_len-1][4]+first.Qty##edited this #if rcv_record[rcv_record_len-1][6] &lt;&gt; first.Units_case or rcv_record[rcv_record-1][3] &lt;&gt; first.Cost: &lt;&lt; THIS PIECE #rcv_record[rcv_record_len-1][7] = (rcv_record[rcv_record_len-1][7]+(first.Units_case/first.Cost))/2.0##edited this&lt;&lt; THIS PIECE #rcv_record_len = len(rcv_record) debugg = 'first' import pdb; pdb.set_trace() first =[] else: tmp = [first.Barcode,first.Cga_type,first.Size,first.Qty*first.Cost,first.Qty,first.Name]#,first.Units_case,(first.Units_case/first.Cost)]&lt;&lt; THIS PIECE AFTER COMMENTS rcv_record.append(tmp) #rcv_record_len = len(rcv_record) debugg = 'second' import pdb; pdb.set_trace() first = [] else: import pdb; pdb.set_trace() tmp = [first.Barcode,first.Cga_type,first.Size,first.Qty*first.Cost,first.Qty,first.Name]#,first.Units_case,(first.Units_case/first.Cost)] &lt;&lt; THIS PIECE AFTER COMMENTS rcv_record.append(tmp) #rcv_record_len = len(rcv_record) first = [] debugg = 'third' import pdb; pdb.set_trace() else: rcv_record[rcv_record_len-1][3] = rcv_record[rcv_record_len-1][3] + (first.Qty*first.Cost) rcv_record[rcv_record_len-1][4] = rcv_record[rcv_record_len-1][4] + first.Qty ## edited this here #if rcv_record[rcv_record_len-1][6] &lt;&gt; first.Units_case or rcv_record[rcv_record-1][3] &lt;&gt; first.Cost: &lt;&lt; THIS PIECE #rcv_record[rcv_record_len-1][7] = (rcv_record[rcv_record_len-1][7]+(first.Units_case/first.Cost))/2.0##edited this &lt;&lt; THIS PIECE debugg = '4th' import pdb; pdb.set_trace() first = [] else: if hasattr(first,'Cga_type'): tmp = [first.Barcode,first.Cga_type,first.Size,first.Cost*first.Qty,first.Qty,first.Name]#,first.Units_case,(first.Units_case/first.Cost)] &lt;&lt; THIS PIECE rcv_record.append(tmp) #rcv_record_len = len(rcv_record) debugg = '5th' import pdb; pdb.set_trace() first = [] else: tmp =[first.Barcode,'','',first.Cost*first.Qty,first.Qty,first.Name]#,first.Units_case,(first.Units_case/first.Cost)] &lt;&lt; THIS PIECE rcv_record.append(tmp) #rcv_record_len=len(rcv_record) debugg = '6th' import pdb; pdb.set_trace() first = [] rcv_record_len = rcv_record_len - 1 </code></pre> <p>If you do a ctrl - f for THIS you will find all the snippets that create problems</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload