Re: Modulo of 4 not working right

2008-07-16 Thread Arien
On Wed, Jul 16, 2008 at 11:01 AM, Marty Alchin <[EMAIL PROTECTED]> wrote: > Of course, you're welcome to go with Scott's suggestion of doing all > the math in one line, but it loses a bit readability going that way. > On the flip side, it probably executes slightly faster, but probably > not enoug

Re: Modulo of 4 not working right

2008-07-16 Thread Ned Batchelder
People here are right: remove the "not". You want to keep adding blanks until the total length is zero mod 4. Then, at line 19 in the dpaste, change the loop to: for blank in range(amountofblanks). You shouldn't be subtracting one from the value there. --Ned. http://nedbatchelder.com Marty

Re: Modulo of 4 not working right

2008-07-16 Thread Marty Alchin
On Wed, Jul 16, 2008 at 11:46 AM, Joshua Jonah <[EMAIL PROTECTED]> wrote: > Yeah, but the point is to make the list exactly divisible, is there a > better way to do this? I'm then taking the number of fields and dividing > them by four, then outputting that number of items in each column. I apolo

Re: Modulo of 4 not working right

2008-07-16 Thread Joshua Jonah
Yeah, but the point is to make the list exactly divisible, is there a better way to do this? I'm then taking the number of fields and dividing them by four, then outputting that number of items in each column. > The 'simple fix', to remove 'not' from the statement works because of > how modul

Re: Modulo of 4 not working right

2008-07-16 Thread Jeff Anderson
Joshua Jonah wrote: I'm not sure how to put the "better fix", would it be in the while statement? should it be child of the statement? I tried the "simple fix" and it isn't working either. It returned a list of 33 items in one of the sections, that would work out to 8.25. Obviously it is div

Re: Modulo of 4 not working right

2008-07-16 Thread Joshua Jonah
I'm not sure how to put the "better fix", would it be in the while statement? should it be child of the statement? I tried the "simple fix" and it isn't working either. It returned a list of 33 items in one of the sections, that would work out to 8.25. Obviously it is divisible, but i dont wan

Re: Modulo of 4 not working right

2008-07-16 Thread Scott Moonen
Joshua, For the simple fix, I think you should remove the word "not" from your while condition. The better fix is to do the math all in one step: amountofblanks += (4 - (len(templist) + amountofblanks) % 4) % 4 -- Scott On Wed, Jul 16, 2008 at 10:30 AM, joshuajonah <[EMAIL PROTECTED]> wrote:

Modulo of 4 not working right

2008-07-16 Thread joshuajonah
I have a form model that is generating a dynamic number of fields. It is using a modulo conditional to see if the amount of fields if divisible by 4 (4 column layout). If it doesn't divide, it adds another field and then tries again. This is not working, it is returning field lists that are 30 (/