Thanks for the response Mike,
I used print only as an example, my actual application code doesn't use print
at all. I replaced the print statement with a call to log.debug such that the
code now looks like this:
...
for i in range(10)
log.debug(i)
...
I am now getting the same error as before, though the trace is different:
Module ddx.controllers.ddxform:49 in storeddx
<< vlist = model.ls()
for i in range(10):
log.debug(i)
log.debug("after for loop")
for cx in vlist:>> log.debug(i)
Module logging:970 in debug
<< if self.manager.disable >= DEBUG:
return
if DEBUG >= self.getEffectiveLevel():
apply(self._log, (DEBUG, msg, args), kwargs)>> if DEBUG >=
self.getEffectiveLevel():
Module logging:1166 in getEffectiveLevel
<< """
logger = self
while logger:
if logger.level:
return logger.level>> while logger:
ValueError: Cannot set attribute to this value
adding extra lines of harmless code above and/or below the for loop does not
change the location at which the error is reported.
Does anyone have any examples of the use of for loops in a controller? A quick
look around the web reveals a distinct lack of published examples where for
loops appear in controllers, is there a reason for this? For loops in
controllers do not need to be ended like they do in templates, correct?
Thanks for your help,
Chris.
> Date: Mon, 16 Feb 2009 21:50:53 -0800
> Subject: Re: Newbie Question: For loops in controllers broken/requires a hack?
> From: [email protected]
> To: [email protected]
>
>
> On Mon, Feb 16, 2009 at 9:34 PM, Chris Van Schaijik
> <[email protected]> wrote:
> >
> > G'day, I've only been playing around with Pylons for a few days
> >
> > Trying to do something really simple, just run a for loop inside a
> > controller action. For the error to occur the loop can be as simple
> > as:
> > ...
> > for i in range(10)
> > print i
> > ...
> >
> > The loop executes, and the numbers 0-9 are printed in the terminal
> > output, however as the loop terminates a server error is reported:
> > "ValueError: Cannot set attribute to this value" and the line the
> > error refers to is the for-loop definition "for i in range(10):"
> >
> > I'd appreciate your thoughts on the matter.
>
> I don't know if this is related, but you're not supposed to use print
> in a Pylons app. You're supposed to use logging instead.
>
> Sometimes Python's traceback gets confused and points to the wrong
> line in the file. This can happen if you modify the file but Python
> doesn't realize it. Sometimes that means it's reading a stray .pyc
> you've forgotten about.
>
> --
> Mike Orr <[email protected]>
>
> >
_________________________________________________________________
Win a Hotmail Go-Kart to race at Bathurst. Enter today!
http://www.livelife.ninemsn.com.au/compIntro.aspx?compId=4602
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---