Actualmente estoy leyendo el capítulo 5.8 de la Inmersión en Python y Mark Pilgrim dice:¿Cómo cambiar el valor de None en Python?
There are no constants in Python. Everything can be changed if you try hard enough. This fits with one of the core principles of Python: bad behavior should be discouraged but not banned. If you really want to change the value of None, you can do it, but don't come running to me when your code is impossible to debug.
yo probamos este en el intérprete
None = "bad"
me siento un SyntaxError: Ninguna asignación a
Solo por curiosidad, ¿cómo cambias a ninguno?
EDIT:
Curiosamente:
>>> import __builtin__
>>> __builtin__.None is None
True
>>> None
>>> None = "bad"
File "<stdin>", line 1
SyntaxError: assignment to None
>>> __builtin__.None = "bad"
File "<stdin>", line 1
SyntaxError: assignment to None
>>> setattr(__builtin__, "None", "bad")
>>> __builtin__.None
'bad'
>>> None
>>> __builtin__.None is None
False
>>> __builtin__.None = None
File "<stdin>", line 1
SyntaxError: assignment to None
también
>>> class Abc:
... def __init__(self):
... self.None = None
...
File "<stdin>", line 3
SyntaxError: assignment to None
>>> class Abc:
... def __init__(self):
... setattr(self,'None',None)
...
>>>
así que supongo 'Ninguno =' simplemente no funciona en cualquier contexto
Creo que 2.3 le dio un SyntaxWarning, fwiw. – perimosocordiae
Gracias por la respuesta, creo que ya no hay amor por los matones en las versiones más nuevas. –
Todavía puede hacer 'True = False' en 2.6 embargo. Y tendrá el efecto que desee. – viraptor