Python Forum
what is the point in function access to globals being read-only? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: what is the point in function access to globals being read-only? (/thread-21322.html)



what is the point in function access to globals being read-only? - Skaperen - Sep-24-2019

what is the point in function access to globals being read-only? referencing objects lets you modify them without the need for a global statement. is there some specific advantage to this?


RE: what is the point in function access to globals being read-only? - Gribouillis - Sep-25-2019

I think it's because there is nothing such as declaring local variables in python. The choice has been made that assigning a value to a variable implicitly declares this variable as local. The consequence is that you cannot assign a value to a global variable without some further declaration, such as a global statement.


RE: what is the point in function access to globals being read-only? - Skaperen - Sep-26-2019

if the global variable exists, already, a read access gets that value instead of its default if not found. for assigning, it does not do the same. i'm wondering about the reasoning for that, since it could do the same. it's just that the default is different. most other languages don't have globals at all, so it's hard to find a comparison. most use some kind of class or function thing to do that. maybe this is why it is considered to be unpythonic to use globals?