need help translating a PHP for statement to python

Eli Pollak none at none.com
Sat Jan 10 10:22:18 CET 2004


Haha ... you must be originally a perl coder. Who else writes attricious
code like this
    if ($bar = (($x_ar[$x] -= $prd + $bar) < 0))
If I was hiring you, I'd fire you on the spot.

Secondly, here is what I came up with. Not sure what '1E7' is though.
And change 'intval' to 'int' if you want to cast something to an int in
python

x,y = cx-cy-1,0
while y <= cy:
    prd = q * y_ar[y] + car - ((car = int(prd / 1E7)) * 1E7);
    if (bar = ((x_ar[x] -= prd + bar) < 0)) x_ar[x] += 1E7;
    x,y = x+1,y+1

Eli



> I'm translating some PHP scripts to Python and have hit a roadblock
> with a for statement.  If someone could explain to me how one should
> translate the multiple increment, evaluations, etc. in the first line
> I would appreciate it deeply ...
>
> for ($y = 0, $x = $cx-$cy-1; $y <= $cy; ++$y,++$x) {
>     $prd = $q * $y_ar[$y] + $car;
>     $prd -= ($car = intval($prd / 1E7)) * 1E7;
>     if ($bar = (($x_ar[$x] -= $prd + $bar) < 0)) $x_ar[$x] += 1E7;
>     }
>
> thanks,
>
> Davis





More information about the Python-list mailing list