TAGS :Viewed: 6 - Published at: a few seconds ago

[ 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:

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:

&gt;&gt;&gt; oS=         262144000
&gt;&gt;&gt; nS=         536870912
&gt;&gt;&gt; usage=       908811325
&gt;&gt;&gt; dE="2013-04-22 10:27:08+00:00"
&gt;&gt;&gt; oS &lt; nS and dE and usage &lt; nS

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.

Answer 1

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...