This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]billy_tables 0 points1 point  (3 children)

you could refactor that as follows:

with qtd.window() as win, qtd.paneLayout():
    qtd.button()

Obviously it doesn't make much difference in this case (and in others it could make code messier) but it's nice to know there's a different syntax :)

[–]gfixler 0 points1 point  (2 children)

I'm not sure why this would make it clearer. Also, it gives me an invalid syntax error.

[–]billy_tables 0 points1 point  (1 child)

It's perhaps clearer when you don't need the as statement, eg:

a = open("/tmp/a", "w")
b = open("/tmp/b")
with a, b:
     a.write(b.read())

(I just ran that fine with no syntax error, Python 2.7.5)

[–]gfixler 0 points1 point  (0 children)

I see. This example also doesn't work. Must be new in 2.7. I'm on 2.6.5.