Importing variables non-deterministic?

Antoon Pardon antoon.pardon at rece.vub.ac.be
Mon Aug 19 05:03:40 EDT 2013


Op 19-08-13 10:32, Chris Angelico schreef:
> On Mon, Aug 19, 2013 at 9:16 AM, Antoon Pardon
> <antoon.pardon at rece.vub.ac.be> wrote:
>> Op 19-08-13 09:45, Dave Angel schreef:
>>> Antoon Pardon wrote:
>>>> I think you are overstating your case. Classes and functions are
>>>> variables too and in general nobody seems to have a problem with them
>>>> being global.
>>>>
>>>
>>> It's global *variables* that are to be avoided.  constants like clsases
>>> and functions are fine.  On the other hand, class attributes can be
>>> variable, and thus are to be avoided when reasonable.
>>
>> Python has no constants. Classes and functions can be changed just like
>> any other variable. I agree that classes and function are generally
>> meant to be constant, but often enought so are global int variables.
> 
> # telnet.py
> IAC = 0xFF
> GA = 0xF9
> WILL = 0xFB
> WONT = 0xFC
> DO = 0xFD
> DONT = 0xFE
> 
> 
> # connection.py
> from telnet import IAC,DO,DONT
> 
> 
> To be sure, Python won't stop me from changing the value of DONT. But
> it's a constant, and its value is defined elsewhere (RFC 854). (In
> this instance, an enum would probably be the better option; but this
> is an example of a more general case.)

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.

-- 
Antoon Pardon



More information about the Python-list mailing list