mirror of
https://github.com/rasbt/python_reference.git
synced 2025-01-18 15:27:09 +00:00
output fix for for-loop leak
This commit is contained in:
parent
3c42a45c60
commit
cb5853e6da
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:70671a8e3f32d21b27867ecdc6d80f3b5c10f00339a2fae3860c4db8930dc7c6"
|
||||
"signature": "sha256:3b7a6d43400c23d25d965b726e6fba3db0b9b0d2d0bbad73c96b8857f8eaa7ee"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -2577,6 +2577,52 @@
|
|||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### In Python 3.x for-loop variables don't leak into the global namespace anymore"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"This goes back to a change that was made in Python 3.x and is described in [What\u2019s New In Python 3.0](https://docs.python.org/3/whatsnew/3.0.html) as follows:\n",
|
||||
"\n",
|
||||
"\"List comprehensions no longer support the syntactic form `[... for var in item1, item2, ...]`. Use `[... for var in (item1, item2, ...)]` instead. Also note that list comprehensions have different semantics: they are closer to syntactic sugar for a generator expression inside a `list()` constructor, and in particular the loop control variables are no longer leaked into the surrounding scope.\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"i = 1\n",
|
||||
"print([i for i in range(5)])\n",
|
||||
"print(i, '-> i in global')"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"[0, 1, 2, 3, 4]\n",
|
||||
"1 -> i in global\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 1
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"In Python 2.x this would print \n",
|
||||
"`4 -> i in global`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
@ -3345,6 +3391,7 @@
|
|||
"metadata": {},
|
||||
"source": [
|
||||
"#### 05/02/2014\n",
|
||||
"- new section in Python 3.x and Python 2.x key differences: for-loop leak<\n",
|
||||
"- new section: Metaclasses - What creates a new instance of a class? \n",
|
||||
"\n",
|
||||
"#### 05/01/2014\n",
|
||||
|
@ -3354,6 +3401,14 @@
|
|||
"- minor fixes of typos \n",
|
||||
"- new section: \"Only the first clause of generators is evaluated immediately\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:1e3a847a38ee33d41e745f74fe6b8a143b9aeb47d0a1e3029ea52899d97687cb"
|
||||
"signature": "sha256:eb9ececefb4c35b16d0496c7f613e4a64bb35b2e9f79b7e049c5b434bd2e6654"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -1076,6 +1076,14 @@
|
|||
"\n",
|
||||
"\"List comprehensions no longer support the syntactic form `[... for var in item1, item2, ...]`. Use `[... for var in (item1, item2, ...)]` instead. Also note that list comprehensions have different semantics: they are closer to syntactic sugar for a generator expression inside a `list()` constructor, and in particular the loop control variables are no longer leaked into the surrounding scope.\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:08b042706cb433ce1f2446c6b6ac00be197268042e605da41164e7d02562766d"
|
||||
"signature": "sha256:3b7a6d43400c23d25d965b726e6fba3db0b9b0d2d0bbad73c96b8857f8eaa7ee"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -2620,7 +2620,7 @@
|
|||
"metadata": {},
|
||||
"source": [
|
||||
"In Python 2.x this would print \n",
|
||||
"`print(4, '-> i in global')`"
|
||||
"`4 -> i in global`"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -3391,6 +3391,7 @@
|
|||
"metadata": {},
|
||||
"source": [
|
||||
"#### 05/02/2014\n",
|
||||
"- new section in Python 3.x and Python 2.x key differences: for-loop leak<\n",
|
||||
"- new section: Metaclasses - What creates a new instance of a class? \n",
|
||||
"\n",
|
||||
"#### 05/01/2014\n",
|
||||
|
@ -3400,6 +3401,14 @@
|
|||
"- minor fixes of typos \n",
|
||||
"- new section: \"Only the first clause of generators is evaluated immediately\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:1e3a847a38ee33d41e745f74fe6b8a143b9aeb47d0a1e3029ea52899d97687cb"
|
||||
"signature": "sha256:eb9ececefb4c35b16d0496c7f613e4a64bb35b2e9f79b7e049c5b434bd2e6654"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -1076,6 +1076,14 @@
|
|||
"\n",
|
||||
"\"List comprehensions no longer support the syntactic form `[... for var in item1, item2, ...]`. Use `[... for var in (item1, item2, ...)]` instead. Also note that list comprehensions have different semantics: they are closer to syntactic sugar for a generator expression inside a `list()` constructor, and in particular the loop control variables are no longer leaked into the surrounding scope.\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user