On 8/21/2010 8:35 PM, Kevin wrote:
> I have attempted to troubleshoot this myself with no luck and am very
> confused why a simple IF statement is not working.  I have used if
> statements in python before and never had such a problem.  I am rather
> glad to see that PRINT outputs to the console, this helps a bit for
> troubleshooting.  Variable information:
> 
> client_id = Comes in from a views request... def
> view_client(request,client_id):
> c.id = Comes in from a database model.
> 
> -- code --
> print "%s - %s" % (str(client_id),str(c.id))
> if str(client_id) == str(c.id):
> -- end --
> 
> The console output, displays 3 - 3 as plain as a day, this is why I am
> very confused on why it is not resolving.  The logic always resolves
> as False, which should resolve as True.  I came to the conclusion that
> both objects were different by using dir() and printing it out to the
> console, hence the reason I now placed both objects inside a str() in
> hopes it may work, but alas, it does not.  If I put it as 3 == 3, it
> resolves as True.  Any ideas?  Placed in str() along with dir(), both
> objects are now equal, but the IF statement sees otherwise.
> 
First of all, the "%s" string formatting code automatically performs an
str() on whatever value is presented, so you could have used

print "%s - %s" % (client_id, c.id)

I would normally use something like

print "/%s/ - /%s/" % (client_id, c.id)

to remove any possibility that white space was causing the problem.

Unfortunately dir() does not give you the information you really need,
which is the type of the information. So you might want to try

print type(client_id), type(c.id)

to give you some more insight into why the equality comparison is
failing.  And be prepared to learn that the comparison *isn't* failing,
but that the logic guarded by the if is not operating the way you think
it does.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to