Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36364 > unrolled thread

Re: When is overriding __getattr__ is useful?

Started byAlbert Hopkins <marduk@letterboxes.org>
First post2013-01-07 11:47 -0500
Last post2013-01-07 11:47 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: When is overriding __getattr__ is useful? Albert Hopkins <marduk@letterboxes.org> - 2013-01-07 11:47 -0500

#36364 — Re: When is overriding __getattr__ is useful?

FromAlbert Hopkins <marduk@letterboxes.org>
Date2013-01-07 11:47 -0500
SubjectRe: When is overriding __getattr__ is useful?
Message-ID<mailman.228.1357577269.2939.python-list@python.org>

On Mon, Jan 7, 2013, at 10:54 AM, Rodrick Brown wrote:
> Can someone provide an example why one would want to override __getattr__
> and __getattribute__ in a class?


They're good for cases when you want to provide an "attribute-like"
quality but you don't know the attribute in advance.

For example, the xmlrpclib uses __getattr__ to "expose" XML-RPC methods
over the wire when it doesn't necessarily know what methods are exposed
by the service.  This allows you do simply do

>>> service.method(*args)

And have the method "seem" like it's just a local method on an object.


There are countless other examples.  But that's just one that can be
found in the standard library.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web