Hello, Thank you, your answer is really clear and does make sense for me!
but unfortunatly it does not fix the problem, using list(), I get an index out of range error in __delitem__ function. there is a traceback here: http://pylonshq.com/tracebacks/e1c0a8d855bd5c39550c1078ee4cfe51 as soon as the problem is fixed i will post an errata on arpress. by the way i'm surprised i found nothing about that as the book is 2 years old now. On 9 nov, 00:16, Marius Gedminas <[email protected]> wrote: > On Mon, Nov 08, 2010 at 07:19:51AM -0800, Yohann REBATTU wrote: > > I'm running into the same issue as you. > > > i'll try to be a bit more specific: > > i my case, it seems the trouble lies in tag removing: > > only one tag on two is actually removed each time, > > > i've no problem with adding tags to page, but removing all four tags > > of one page will remove the first and third tags of the page but not > > the second neither the fourth. > > This *sounds* like you're doing something like > > for tag in page.tags: > page.tags.remove(tag) > > which fails, since when the for loop moves to position #2 in the list, item > #1 has already been deleted and item #3 was shifted into position #2. > > The simplest fix is > > for tag in list(page.tags): > page.tags.remove(tag) > > because then you're iterating over a copy of the list which doesn't > change when you remove tags. > > > On Oct 8, 3:40 pm, Stratos Papadopoulos <[email protected]> wrote: > > > More specifically the code in: > > > >http://pylonsbook.com/en/1.1/simplesite-tutorial-part-2.html#tags-man... > > > > and the update_tags() action. > > Here it is: > > def update_tags(self, id=None): > ... > for i, tag in enumerate(page.tags): > if tag.id not in self.form_result['tags']: > del page.tags[i] > ... > > and it's doing exactly what I thought. If you change it to > > for i, tag in enumerate(list(page.tags)): > if tag.id not in self.form_result['tags']: > del page.tags[i] > > it should work (disclaimer: I haven't tested the fix). > > If I'm right, can you please report the error > athttp://apress.com/book/errata/773? Something like > > "Chapter 14, section Adding Tags To Pages, in update_tags() > the for loop should be > > for i, tag in enumerate(list(page.tags)): > > instead of > > for i, tag in enumerate(page.tags): > > otherwise when you remove tags, every second tag will > erroneously persist." > > Marius Gedminas > -- > Photons have energy, and trying to cram too many into too small of a space can > cause a black hole to form, which is, needless to say, not a desirable trait > for an optical computer. > --http://scottaaronson.com/blog/?p=261#comment-13693 > > signature.asc > < 1 000AfficherTélécharger -- 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.
