[Python-Dev] Python FAQ: Why doesn't Python have a "with" statement?

Georg Brandl g.brandl at gmx.net
Sat Jun 14 21:33:40 CEST 2008


Cesare Di Mauro schrieb:

> Also, taking the Tk example that I used, it can be changed in the following way:
> 
>        on Button(self) as b:
>            b.text = "QUIT"
>            b.fg = "red"
>            b.command = self.quit
>  
>            pack({"side": "left"})
>  
>        on Button(self) as b:
>            b.text = "Hello"
>            b.command = self.say_hi
>  
>            pack({"side": "left"})
> 
> Using a syntax which reseambles the with one.

So what is the advantage to

b = Button(self)
b.text = "QUIT"
b.fg = "red"
b.command = self.quit

?

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.



More information about the Python-Dev mailing list