Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the "from __future__ import braces" code?

I was wondering what is exactly the code that executed on the command:

>>> from __future__ import braces SyntaxError: not a chance 

so, since python is open-sourced I opened C:\Python27\Lib\__future__.py and looked. surprisingly, I found nothing there that handle importing braces module.

so, my question is, where is the code that handle this? what happen when I run that command?

like image 644
Elisha Avatar asked Jan 14 '14 22:01

Elisha


People also ask

What is __ future __ in Python?

__future__ module is a built-in module in Python that is used to inherit new features that will be available in the new Python versions.. This module includes all the latest functions which were not present in the previous version in Python. And we can use this by importing the __future__ module.

Can I use braces in Python?

In fact, Python supports curly braces, BEGIN/END, and almost any other language's block schemes: see python.org/doc/humor/…!


1 Answers

The code is in future.c:

future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename) ...   else if (strcmp(feature, "braces") == 0) {     PyErr_SetString(PyExc_SyntaxError,         "not a chance");     PyErr_SyntaxLocation(filename, s->lineno);     return 0;   } 
like image 62
Peter de Rivaz Avatar answered Oct 02 '22 20:10

Peter de Rivaz