3 ms·
> Notice data is defined inside the with block, but remains accessible once that block is exited (and the file object is auto-closed). This is the normal Python
by svisser 11y ago
> Notice data is defined inside the with block, but remains accessible once that block is exited (and the file object is auto-closed). This is the normal Python scoping rules at work. If you create (initially define) a variable in a block, it's also defined in the parent blocks - up until the function boundary.
The with statement doesn't create a new scope and as such it's the same as variables defined outside a with statement.
- fancy_pantser 11y agoMaybe he's coming from Perl or something with narrow scoping.