<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Nick Coghlan wrote:
<blockquote cite="mid45D1BF19.6030706@gmail.com" type="cite">
<pre wrap="">I've tried this out on Brett's urllib & urllib2 examples below. (calling
the new builtin attrview() to emphasise the fact that it retains a
reference to the original instance).</pre>
</blockquote>
<br>
Ooh, ooh! I wanna change my vote! +1 on attrview(), +0.25 on ".[]".<br>
<br>
Maybe I haven't written enough Python, but I don't think you need this
specialized form of accessing attributes very often. So I've shifted
to the "new syntax seems like overkill" camp. Besides, once you've got
the attrview() you can use all the existing dict syntax and it looks
totally clean. The original example:<br>
setattr(self, method_name, getattr(self.metadata, method_name)<br>
which became in the new syntax:<br>
self.[method_name] = self.metadata.[method_name]<br>
would be:<br>
attrview(self)[method_name] = attrview(self.metadata)[method_name]<br>
And an attrview lets you use get() and the in operator. Plus, if you
were performing a lot of operations on attributes all at one go, you'd
cache it in a local and then it'd look even better.<br>
<br>
Perhaps object.__attrs__() returns a view on the object's attributes,
and attrview() is simply a convenience function.<br>
<br>
<br>
<i>larry</i>
</body>
</html>