views:

131

answers:

3

This is a follow up to my other question.

I thought that

    mylist = list(Rep().all().fetch(50))

makes mylist a list. But when I try to get its length I get the message

self.response.out.write(len(P))
TypeError: object of type 'Rep' has no len()

Can anyone explain what I am doing wrong?

    Rep().replist = L                                   
    Rep().put()                              
    mylist = list(Rep().all().fetch(50))
    P = mylist.pop()
    self.response.out.write(len(P))

UPDATE

As a reference for others who may encounter the same problem; I post the following table which was very helpful to me. (The original here)

Rep().........................Rep object 
Rep.all().....................Query object 
list(Rep.all())...............List of Rep objects. 
list(Rep.all())[0]............A single Rep object 
list(Rep.all())[0].replist....A list

Thanks for all the answers.

A: 

self.response.out.write(len(mylist))

demas
@demas: len(mylist) returns the number of lists in mylist. I assume that P = mylist.pop() would pop the last list in mylist. And I want to print the elements of that popped list. But as DonaldlsFreak mentions what is popped is not a list but a "Rep" instance. Sorry, I don't understand why the list L I saved to datastore is not returning. Or what is the best way to do this simple database operation? Thanks again.
Zeynel
A: 

if you want to print the number of elements of replist property.

self.response.write(len(P.replist));

Hope i can help you :p

DonaldIsFreak