This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Paul.Wiseman
Recipients Paul.Wiseman
Date 2012-09-28.03:02:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1348801354.79.0.991137546164.issue16068@psf.upfronthosting.co.za>
In-reply-to
Content
I found this behaviour today and thought it was weird so asked the question on SO here http://stackoverflow.com/questions/12632894/why-doesnt-getattr-work-with-exit/12632972#12632972

basically if I attributes are returned dynamically, they seem to get overlooked by the code that runs the with statements.

>>> class FileHolder(object):
...    def __init__(self,*args,**kwargs):
...        self.f= file(*args,**kwargs)
...    def __getattr__(self,item):
...        return getattr(self.f,item)
...
>>> a= FileHolder("a","w")
>>> a.write
<built-in method write of file object at 0x018D75F8>
>>> with a as f:
...   print f
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: __exit__
>>> a.__exit__
<built-in method __exit__ of file object at 0x018D75F8>
History
Date User Action Args
2012-09-28 03:02:34Paul.Wisemansetrecipients: + Paul.Wiseman
2012-09-28 03:02:34Paul.Wisemansetmessageid: <1348801354.79.0.991137546164.issue16068@psf.upfronthosting.co.za>
2012-09-28 03:02:34Paul.Wisemanlinkissue16068 messages
2012-09-28 03:02:33Paul.Wisemancreate