gadss
gadss

Reputation: 22489

how to check empty column in python

how can i check if i have an empty column in my queryset?

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 try also in my code to become:

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

but it also print :

[None]

thanks in advance...

Upvotes: 4

Views: 4412

Answers (3)

Karl Barker
Karl Barker

Reputation: 11341

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

>>> a = [None]
>>> a == [None]
True

Upvotes: 0

7O'clock
7O'clock

Reputation: 41

Shouldn't the expression be like:

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

In case that you're looking for an empty list.

Upvotes: 0

Neel
Neel

Reputation: 21243

You have to check the values of the column

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

Upvotes: 3

Related Questions