[Python-ideas] Bug? Feature? setattr(foo, '3', 4) works!

Cem Karan cfkaran2 at gmail.com
Mon Dec 22 14:44:50 CET 2014


On Dec 22, 2014, at 7:43 AM, Sturla Molden <sturla.molden at gmail.com> wrote:

> On 19/12/14 05:27, Cem Karan wrote:
> 
>> I'd like to suggest that getattr(), setattr(), and hasattr() all be modified so that syntactically invalid statements raise SyntaxErrors.
> 
> 
> I'd like to object! This would break a lot of code that depends on HD5 and NetCDF databases, e.g. PyTables.
> 
> Often we can do
> 
>   table.x
> 
> but sometimes we need to do
> 
>   getattr(table,'some long field name')
> 
> A lot of scientific software depends on this, and it would break at the moment your proposal is introduced. It would be a major disaster. It would even set back NASA's space program (no kidding!)

Yup, someone else pointed out that ctypes also relies on the current behavior, so I dropped the suggestion.  (To the person that pointed about ctypes, I apologize about not giving you credit, but I deleted the email).

Thanks,
Cem Karan


More information about the Python-ideas mailing list