python file versioning

Diez B. Roggisch deetsNOSPAM at web.de
Mon Oct 25 10:39:01 EDT 2004


Jeff Epler wrote:

> No, that's completely incorrect.
> 
>   File "/tmp/diez.py", line 4
>       from __future__ import nifty_feature
> SyntaxError: from __future__ imports must occur at the beginning of the
> file

Oops - I didn't know that. But it makes sense - as it possibly affects
parsing behaviour it has to be like that.

But _completely_ is a bit strong - other version-dependend code can be
written like that, and if you encapsulate the version depenend code in
modules, you can still import them like this:


file mod_22:
from __future__ import nifty_feature
import bar

file mod_23:
import bar


app.py:

import sys

if sys.version_info[:2] == (2,2):
    import mod_22 as mod
else:
    import mod_23 as mod


So I think I showed the OP a way to deal with version-dependencies.

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list