And in my case, I'll use the python newbie defense! I'm not sure how long that card is good for, so I've got to use it while I can. :)
Let me assess the difference between the three: 1) Ben's solution, web.header() is set on class instantiation, and in addition his base class can be inherited by other classes beyond his hello class. 2) My solution, web.header() is also set on class instantiation, but within the hello class. 3) Anand's solution, web.header() is set on every call to the hello class's GET function. If my assessment is correct, I would think either #1 or #2 would be faster (negligibly so to the point of not really mattering, I would guess) because the header is only set once, and #1 is more flexible than #2 as the header can be easily applied to other classes. Pete On Thu, Jun 2, 2011 at 4:03 AM, Ben Hearsum <[email protected]> wrote: > In my case, all of my controllers use the same content type, so it > made sense to create a base class. > > On Jun 2, 1:59 am, Anand Chitipothu <[email protected]> wrote: >> 2011/6/2 Pete Emerson <[email protected]>: >> >> > Aha, thank you, Ben! After putting in your solution and seeing it >> > work, I tried to get the headers in the hello class, and it works (and >> > the simple nosetest I wrote works too): >> >> > class hello: >> > def __init__(self): >> > return web.header('Content-Type', 'text/html') >> >> > def GET(self): >> > return 'Hello, world!' >> >> > As to whether this is the 'right' or 'best' way, I don't know. But it >> > works. >> >> Why not this? >> >> class hello: >> def GET(self): >> web.header('Content-Type', 'text/html') >> return "Hello, world!" > > -- > You received this message because you are subscribed to the Google Groups > "web.py" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/webpy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
