PEP 260: simplify xrange()

Martin von Loewis loewis at informatik.hu-berlin.de
Sun Jul 1 12:32:15 CEST 2001


"Tim Peters" <tim_one at email.msn.com> writes:

> Rather than play with version numbers, it's usually better to use exec or
> eval in a try/except block to determine *directly* whether the feature you
> need is there.  In the case of new syntax, the outcome can be used to import
> either a "new style" or "old style" version of a module, thus sidestepping
> the "old version can't even compile some new forms of code" gotcha.

In my experience, if you need to support older versions, it is best to
abstain from new syntax. Much of the new syntax is there for
convenience; however, this is outweighed by the inconvenience of
having to maintain two modules.

Even for features that have no equivalent in older versions
(e.g. Unicode literals), it is still better to use old syntax
(e.g. calling unicode() instead); this might allow to emulate the
missing feature for older versions.

Regards,
Martin



More information about the Python-list mailing list