How to check empty column in python

How can I check if I have an empty column in my query?

this is my code:

mastercard_percent = ClientPaymentOption.objects.filter(name='MasterCard', client=client).values_list('itemcharged',flat=True) if mastercard_percent == [None]: print 'empty' print mastercard_percent 

and I got only this:

 [None] 

I am also trying in my code to become:

  if mastercard_percent == [None]: print 'empty' print mastercard_percent 

but he also prints:

 [None] 

thanks in advance...

+4
source share
3 answers

You should check the column values

like if not mastercard_percent[0]: print 'empty'

+3
source

There should be no expression:

 print 'empty' if mastercard_percent == [] print mastercard_percent 

If you are looking for an empty list.

0
source

What is the output of repr(mastercard_percent) ? If its value is really [None] , then a comparison with [None] should work:

 >>> a = [None] >>> a == [None] True 
0
source

Source: https://habr.com/ru/post/1398556/


All Articles