Message171399
| 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:34 | Paul.Wiseman | set | recipients:
+ Paul.Wiseman |
| 2012年09月28日 03:02:34 | Paul.Wiseman | set | messageid: <1348801354.79.0.991137546164.issue16068@psf.upfronthosting.co.za> |
| 2012年09月28日 03:02:34 | Paul.Wiseman | link | issue16068 messages |
| 2012年09月28日 03:02:33 | Paul.Wiseman | create |
|