sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

print function doesn't work as expected #100

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1.
a = [round(kk) for kk in [1.1,2.2,3.3]]
print a

2.
a = [round(kk) for kk in [1.1,2.2,3.3]]
print(a)

3.
b = [1.0,2.0,3.0]
print b

4.
b = [1.0,2.0,3.0]
print(b)

5.
print [value for value in [1.0,2.0,3.0]]

6.
print([value for value in [1.0,2.0,3.0]])

What is the expected output? What do you see instead?

Expected output:
1. [1.0,2.0,3.0]
2. [1.0,2.0,3.0]
3. [1.0,2.0,3.0]
4. [1.0,2.0,3.0]
5. [1.0,2.0,3.0]
6. [1.0,2.0,3.0]

Real output from the brython console 
(http://www.brython.info/tests/console_en.html):
1.
SyntaxError: token id after (id) print:
module '__main__' line 2
print a
       ^
2.
RuntimeError: TypeError: x.__str__ is not a function
module '__main__' line 2
for kk in [1.1,2.2,3.3]:

3. same output than 1.

4. same output than 2.

5.
SyntaxError: token for after (sub) (expr false) (id) value:
module '__main__' line 1
print [value for value in [1.0,2.0,3.0]]
             ^

6.
RuntimeError: TypeError: x.__str__ is not a function
module '__main__' line 3
    res7g933c0t.append(value )

What version of the product are you using? On what operating system?

Brython version 1.1.20130311-212902 tested on Windows XP 32 bits, Xubuntu 12.04 
and Ubuntu 12.04

Please provide any additional information below.
If I do:
b = [1.0,2.0,3.0]
print b[0],b[1],b[2]      # This fails
print(b[0],b[1],b[2])     # This works

The first print doesn't work and the error is:
SyntaxError: token id after (id) print:
module '__main__' line 2
print b[0],b[1],b[2]
       ^

I suppose print behaviour is for python 3 and python 2 behaviour is not 
supported.

All the best

Original issue reported on code.google.com by kikocorr...@gmail.com on 13 Mar 2013 at 10:25

GoogleCodeExporter commented 9 years ago
Since Brython is based on the Python3 syntax, "print x" raising a SyntaxError 
is the expected result
But you are right about the other examples, they are a side effect of the 
recent changes in attribute resolution. It will be fixed with the almost 
finished new version

Original comment by pierre.q...@gmail.com on 13 Mar 2013 at 3:51

GoogleCodeExporter commented 9 years ago
The bug was fixed in revision 714

Original comment by pierre.q...@gmail.com on 17 Mar 2013 at 9:11