Thoughts on using isinstance

Duncan Booth duncan.booth at invalid.invalid
Wed Jan 24 13:29:35 EST 2007


Gabriel Genellina <gagsl-py at yahoo.com.ar> wrote:

> In 
> the example above, you can validate that fileobject has a write 
> attribute: getattr(fileobject, "write"). But I'd only do that if I 
> have a good reason (perhaps if the file is used after some lengthy 
> calculation,and I want to be sure that I will be able to store the
> result) 

Or even just:

   write = fileobject.write
   data = ... lengthy calculation here ...
   write(data)

There is no point using getattr when you know the name of the attribute in 
advance.



More information about the Python-list mailing list