Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

with statement - backport for Python 2.5

I'd like to use with statement in Python 2.5 in some production code. It was backported, should I expect any problems (e.g. with availability/compatibility on other machines/etc)?

Is this code

from __future__ import with_statement

compatible with Python 2.6?

like image 898
gorsky Avatar asked Dec 09 '22 18:12

gorsky


2 Answers

Yes, that statement is a no-operation in Python 2.6, so you can freely use it to make with a keyword in your 2.5 code as well, without affecting your code's operation in 2.6. This is in fact the general design intention of "importing from the future" in Python!

like image 108
Alex Martelli Avatar answered Dec 14 '22 22:12

Alex Martelli


You can call this in Python 2.6 and 3.0/1 without problems (it's a no-op there).

like image 25
Tim Pietzcker Avatar answered Dec 14 '22 23:12

Tim Pietzcker