File tree 1 file changed +3
-15
lines changed
1 file changed +3
-15
lines changed Original file line number Diff line number Diff line change @@ -125,23 +125,11 @@ used, an :exc:`UnboundLocalError` exception is raised.
125
125
If a name binding operation occurs anywhere within a code block, all uses of the
126
126
name within the block are treated as references to the current block. This can
127
127
lead to errors when a name is used within a block before it is bound. This rule
128
- is subtle::
129
-
130
- >>> x = 1
131
- >>> def new_scope():
132
- ... print(x)
133
- ... x = 2
134
- ...
135
- >>> new_scope()
136
- Traceback (most recent call last):
137
- File "<stdin>", line 1, in <module>
138
- File "<stdin>", line 2, in new_scope
139
- UnboundLocalError: local variable 'x' referenced before assignment
140
-
141
- Python lacks declarations and allows name binding operations to
128
+ is subtle. Python lacks declarations and allows name binding operations to
142
129
occur anywhere within a code block. The local variables of a code block can be
143
130
determined by scanning the entire text of the block for name binding operations.
144
- See also :ref: `the FAQ entry on UnboundLocalError <faq-unboundlocalerror >`.
131
+ See :ref: `the FAQ entry on UnboundLocalError <faq-unboundlocalerror >` for some
132
+ examples.
145
133
146
134
If the :keyword: `global ` statement occurs within a block, all uses of the names
147
135
specified in the statement refer to the bindings of those names in the top-level
You can’t perform that action at this time.
0 commit comments