You're the man, and about the float() thing, i couldn't get it to work before and that fixed it believe it or not.
I'm still having trouble with this but in another area, I'll dpaste a bunch and post it. Marty Alchin wrote: > On Tue, Jul 15, 2008 at 2:19 PM, joshuajonah <[EMAIL PROTECTED]> wrote: > >> White forever, never loads in the browser. I have changed it today, >> but i cannot figure out what i screwed up. >> >> http://dpaste.com/hold/65163/ >> >> It makes a ton of checkboxes in four columns, it then adds blank >> fields for new options until it is divisible by 4 so that it fits the >> 4 column layout right. >> > > >From what I can tell, your "divisiblebyfour" function is your problem. > Namely, you're usign "is" in a way it's not supposed to be used. > > "is" is Python's way of determining if two references point to the > same object, not whether two objects are equivalent. This is typically > used with complex objects that define a method to deal with it, but > it's a little tricky for things like numbers. Consider the following > interactive interpreter session: > > >>>> 0 is 0 >>>> > True > >>>> 0.0 is 0.0 >>>> > True > >>>> 0.0 is 0 >>>> > False > >>>> test = 0 >>>> test is 0 >>>> > True > >>>> test = 0.0 >>>> test is 0.0 >>>> > False > > And, to be clear about your specific case: > > >>>> float(8) % float(4) >>>> > 0.0 > >>>> float(8) % float(4) is 0.0 >>>> > False > >>>> float(8) % float(4) is 0 >>>> > False > > Because you're using "is not" in your function, that expression will > *always* be True, and your function will *always* return False, > regardless of what input you give it. Since you looping over it "while > not divisiblebyfour(...)", that test will *always* succeed and your > loop will *never* end. However, look what happens when we use the > appropriate operator, "==". > > >>>> 0.0 == 0.0 >>>> > True > >>>> 0 == 0 >>>> > True > >>>> 0.0 == 0 >>>> > True > >>>> float(8) % float(4) == 0.0 >>>> > True > >>>> float(8) % float(4) == 0 >>>> > True > >>>> 8 % 4 == 0 >>>> > True > >>>> 7.5 % 2.5 == 0 >>>> > True > >>>> 10 % 2.5 == 0 >>>> > True > > Note those last ones, too. You don't need to cast to floats for the > modulo to work properly, so it's a bit unnecessary. Also, any number > other than zero evaluates to True on its own anyway, so you don't even > need that if block in the function. Better yet, with those things > taken out, that function gets so small that you can just get rid of it > if you want: > > while not (len(templist) + amountofblanks) % 4: > amountofblanks += 1 > > That'll work quite well for what you're doing, without dealing with an > extra function and all the hassle. Hope this helps. > > -Gul > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---