我索引到一個列表這樣Python的索引到一個列表,並得到一個錯誤,我不應該得到
if first.Barcode == rcv_record[rcv_record_len-1][0]:
do stuff
first.Barcode
是一個字符串rcv_record
的是,像這樣的列表[[],[],[]]
像這樣- 和
rcv_record_len
是len(rcv_record)
它工作正常,現在它說unsupported opperand - on int and list
但1和rcv_record_len
都是ints。任何人有任何線索?
編輯我添加到這個列表的方式是通過擴大TMP列表,然後附加到rcv_record
我開始認爲這是一個錯誤或東西。取消註釋和評論之後同樣的錯誤就具有此代碼
if hasattr(first,'Cga_type'):
它有沒有關係,雖然
而且我使用PDB,並通過代碼加強和上午整數同樣的錯誤,另一條線彈出複製和粘貼有問題的作品,它可以工作,但只要我沒有調試器運行就會中斷。
我已經編輯了
tmp.extend([first.Units_case])
tmp.extend([(first.Units_case)/(first.Cost)])
和註釋掉哪裏,這是絕不會使用或引用,並一切正常,因爲它應該的代碼。這是爲了證明這個問題不是我目前所擁有的,而是與這個新的片段有關,無論出於何種原因都會破壞一切。這些添加後,我得到奇怪的opperand int列表錯誤。
這是野獸,這是我知道的殘骸,但這個項目只是在我的膝蓋上。
if Type == 'burn rate':
RcvRecords = []
RmvRecords = []
while broken_item_len > 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 > 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]) << THIS PIECE
#tmp.extend([(first.Units_case)/(first.Cost)]) << 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] <> first.Units_case or rcv_record[rcv_record-1][3] <> first.Cost: << 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<< 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)]<< 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)] << 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] <> first.Units_case or rcv_record[rcv_record-1][3] <> first.Cost: << 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 << 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)] << 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)] << 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
如果你做一個CTRL - f有關這一點,你會發現所有的製造問題
你能提供更多的周邊代碼嗎?如果你在那條線上得到這個錯誤,那麼這個變量絕對不是你認爲的那種類型。 –
同上。 rcv_record_len在哪裏定義和rcv_record? –
在'if'之前打印'rcv_record_len' – Ofiris