我正在索引这样的列表
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
都是整数。有人有任何线索吗?
编辑我添加到此列表的方式是扩展一个 tmp 列表,然后附加到 rcv_record
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)]) << 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]:
我开始认为有一个错误或什么的。取消注释并对其进行注释后,在具有此代码的另一行上会弹出相同的错误
if hasattr(first,'Cga_type'):
但这与整数相同的错误无关
此外,我正在使用 pdb 并单步执行代码并复制和粘贴有问题的部分,它可以工作,但是一旦我在没有调试器的情况下运行它就会中断。
我已经编辑了
tmp.extend([first.Units_case])
tmp.extend([(first.Units_case)/(first.Cost)])
并注释掉曾经使用或引用过的代码,并且一切正常。这是为了证明问题不在于我目前拥有的东西,而在于这个新片段,无论出于何种原因,它都会破坏一切。添加这些之后,我得到了奇怪的操作数 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 ,您将找到所有产生问题的片段