[Chicago] How do you troubleshoot cgi errors?
Ian Bicking
ianb at colorstudy.com
Mon Jul 23 19:56:48 CEST 2007
David Rock wrote:
> * Ian Bicking <ianb at colorstudy.com> [2007-07-23 12:28]:
>> It's actually a tee for any kind of object. Any method that is called
>> gets called on all the sub-objects (self.files in this case). It only
>> returns the return value of the last object, but for files you write to
>> there's no meaningful return values anyway. Similarly it doesn't handle
>> attributes, since it treats everything like a method.
>>
>> The __getattr__ method is called when the object has no other attribute
>> -- i.e., if you call obj.foo, then obj.__getattr__('foo') is called (if
>> the object has a __getattr__ method, and no foo attribute). When you
>> call obj.foo(x), then obj.__getattr__('foo')(x) is called.
>>
>> In ReplStdOut whenever you call obj.anything, you get a function back.
>> When you call that function, it gets subobject.anything from every
>> subobject, and calls that with the arguments you pass in. The function
>> it returns is called a "closure", because the function object remembers
>> the value of "self" and "attr" even though they aren't explicit
>> arguments to the function. That's all a closure really is -- a function
>> that remembers some extra values.
>
> Wowsers. I'm gonna have to chew on that one a little bit. I really
> like it, though. I don't suppose you have any ideas of where to look
> for further reading on the concepts, do you?
I guess there's a bunch of pieces. There's getattr(), which you can
read up on here:
http://www.diveintopython.org/power_of_introspection/getattr.html
I don't see a lot online on __getattr__. Huh. Maybe that's why I
encounter so many people who are surprised about it. The reference docs
for that are here: http://python.org/doc/current/ref/attribute-access.html
For first class functions you might look at Dive Into Python's
functional section:
http://diveintopython.org/functional_programming/index.html
For closures I'm not sure... some of the material out there is really
more complex than it needs to be. Maybe just reflect on this, the
simplest of closures:
def make_returner(return_value):
def returner():
return return_value
return returner
x = make_returner(1)
y = make_returner(2)
x()
y()
But I dunno. There's a lot of debate out there about closures,
functional programming, etc, none of which illuminates the issue. So
try not to get distracted by that stuff.
--
Ian Bicking : ianb at colorstudy.com : http://blog.ianbicking.org
: Write code, do good : http://topp.openplans.org/careers
More information about the Chicago
mailing list