java2python icon indicating copy to clipboard operation
java2python copied to clipboard

assignment expressions in while loop

Open yucer opened this issue 9 years ago • 0 comments

Hello,

I'll put some feed back here to some missing conversions. I hope it can be useful.

A java code like this:

int amountRead;
while((amountRead = is.read(buffer, 0, 1024))!= -1)
{
    decoded.write(buffer, 0, amountRead);
}
decoded.flush();

is converted to this python one:

amountRead = int()
while (amountRead = is_.read(buffer_, 0, 1024)) != -1:
    decoded.write(buffer_, 0, amountRead)
decoded.flush()

The problem is that Python doesn't allow assignment expressions to be used inside the conditional expression of the loop. Check here: expression vs assignments in while loop in python and Java?

yucer avatar Sep 27 '16 09:09 yucer