Importing variables non-deterministic?

Peter Otten __peter__ at web.de
Mon Aug 19 05:49:48 EDT 2013


Chris Angelico wrote:

> On Mon, Aug 19, 2013 at 10:03 AM, Antoon Pardon
> <antoon.pardon at rece.vub.ac.be> wrote:
>> This is irrelevant. That some context defines a constant, and that you
>> can use a variable with the same name as a constant in python, doesn't
>> contradict the statement that python (as a language) doesn't has
>> constants. There is nothing in the language that would prevent buggy
>> code from changing any of those variables. So from a python point of
>> views these are just global variables. Just as the struct_global.y was
>> in the original contribution.
> 
> And there's nothing preventing a program from using ctypes to
> overwrite an object's refcount, thus causing a segfault. So? The issue
> was regarding imports, and it's perfectly safe to import a constant,
> even if the interpreter doesn't protect you from then being a total
> idiot and changing it.

Come on, breaking a "gentlemen's agreement" by rebinding a name and using 
ctypes to manipulate the internal state of the cpython imlementation are 
very different things. If that proves anything I'll best you with a Python 
script that controls a robot which in turn destroys the computer running the 
script with a hammer ;)

If Antoon's point is that global "constants" in Python are only constants 
because the programmer thinks of them that way I'd say that's an important 
addition to put Steve's "global variables are considered harmful" into 
perspective.




More information about the Python-list mailing list