On a second thought....
probably the index method compares with == and not "is". as in
def index(list,value):
for k,vin enumerate(list):
if v==value: return k
raise ValueError, "%s is not in list" % value
while it should do
def index(list,value):
for k,vin enumerate(list):
if v is value: return k
raise ValueError, "%s is not in list" % value
in your case
db.todo.t_anything == 'anything' is a query therefore is not false.
I do not know why index works that way.
On Thursday, 16 August 2012 11:09:56 UTC-5, Massimo Di Pierro wrote:
>
> Cannot reproduce:
>
> >>> a=[1,2,3]
> >>> a.index(0)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: 0 is not in list
>
> On Thursday, 16 August 2012 08:31:51 UTC-5, simon wrote:
>>
>> Please can someone explain why, for a list of fields, that
>> fields.index("anything at all") always evaluates to 0.
>>
>> For example this prints 23 and 0.
>>
>> t=db.todo
>> fields = [t.id, t.customer, t.subject, t.completed, t.modified_by]
>> if 23 in fields: print("23 is in there")
>> print(fields.index("hshshshs"))
>>
>>
>> ........what I want to do is remove a field from a list of fields
>> <fields.remove(t.customer)> just removes the first field in the list.
>>
>>
>>
--