DanH
DanH

Reputation: 5818

If and statement equating to True, but should be False

So I have the following code:

if old_size < new_size and date_exceeded and usage(user) < new_size:
    unset_date_exceeded()

The problem is this is evaluating to True even when the values suggest otherwise:

logger.info('oS:%s | nS:%s | dE:%s | usage:%s' % (old_size, new_size, date_exceeded, usage(user)))
# returns oS:262144000 | nS:536870912 | dE:2013-04-22 10:27:08+00:00 | usage:908811325

Notice that usage(user) < new_size should be False but for some reason it's not working out that way.

I thought maybe I didn't understand how and functions, but if I try this in a python shell I can't replicate it and instead get the expected result:

>>> oS=         262144000
>>> nS=         536870912
>>> usage=       908811325
>>> dE="2013-04-22 10:27:08+00:00"
>>> oS < nS and dE and usage < nS
False

I'm fairly certain I'm losing my mind and missing a typo or something, so apologies if that's the case, but I am stumped a good'un.

Upvotes: 1

Views: 153

Answers (1)

Jon Clements
Jon Clements

Reputation: 142166

I suspect you're trying to compare different types (which are allowed - but the meaning is somewhat pointless)...

If you try:

print map(type, (old_size, new_size, date_exceeded, usage(user)))

And then go from there...

Upvotes: 1

Related Questions