[Python-ideas] import features; if "print_function" in features.data

Nick Coghlan ncoghlan at gmail.com
Sat May 30 15:25:45 CEST 2015


On 30 May 2015 at 22:54, Wes Turner <wes.turner at gmail.com> wrote:
> Would it be useful to have one Python source file with an OrderedDict of
> (API_feat_lbl, [(start, None)]) mappings
> and a lookup?

Your choice of example means I'm not sure what additional capabilities
you're seeking.

The __future__ module already aims to cover this for compiler directives:

>>> import __future__
>>> __future__.all_feature_names
['nested_scopes', 'generators', 'division', 'absolute_import',
'with_statement', 'print_function', 'unicode_literals']
>>> __future__.print_function
_Feature((2, 6, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 65536)

If you're looking for particular builtins, importing builtins (Python
3) or __builtin__ (Python 2) and checking attributes lets you see what
is available via hasattr().

hasattr() will also cover most feature check needs for other modules
(file descriptor support in the os module is an exception, hence the
related dedicated query APIs for that).

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list