natural / java2python

Simple but effective library to translate Java source code to Python.
GNU Lesser General Public License v2.1
564 stars 243 forks source link

assignment expressions in while loop #45

Open yucer opened 8 years ago

yucer commented 8 years ago

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?