General statistics
List of Youtube channels
Youtube commenter search
Distinguished comments
About
Anony Mousse
Indently
comments
Comments by "Anony Mousse" (@anon_y_mousse) on "How to use Context Managers in Python Tutorial" video.
I've been meaning to look up how Python handles this construct, so thanks for saving me the trouble. I still have a few questions though. Can you omit the "as foo" portion of the header? If it lets you do that, how does it handle resolving function calls in scope? Say you have a write function in the scope of the file object, if you were to just call write directly, would it automatically call the correct one that applies to that object, or would it go to a globally scoped write function?
2
@eliavrad2845 Okay, so it doesn't use it as a default scope then? For instance, using your example, you couldn't replace `text = f.read()` with `text = read()` and it work appropriately through the file object that denotes the inner scope? And also, Python doesn't have an underscore as default notation, right?
1
@eliavrad2845 That's a shame. It'd be more useful if it allowed anonymous access as a new scope with a default object. Although, I can understand why they had to limit it in this way since Python doesn't have a scope resolution operator.
1