I did a query to get all the field values from a model.I stored the result in a queryset.
queryset=Books.objects.filter(book_type="comic")
Now when i filter this queryset :
query=queryset.filter(~Q(auther_id=1))
autherList=[]
for q in query:
autherList.append(q.auther_id)
print autherList
It print the list as:
[3L, 4L, 9L, 13L, 53L, 53L, 102L, 111L, 111L, 111L, 111L]
My question is : What does this L signify and how to remove it to get a simple list of ids.
I looked over this but could not find anything regarding this.
The L denotes that the items are of long type.
The underlying database library (mysql may be?) is creating the long types while fetching them from the db. So they are long instead of plain old int.
You can convert them to integers using the int function.
>>> lng_number = 23L
>>> int_num = int(lng_number)
>>> int_num
23
If all the values are of the long type, you can use map like this:
>>> long_list = [1L, 3L, 10L]
>>> int_list = map(int, long_list)
>>> int_list
[1, 3, 10]
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With