[Twisted-Python] Deferred instance has no attribute '__getitem__' ??????

Ken MacDonald drken567 at gmail.com
Fri Jul 16 09:32:08 EDT 2010


Thanks for the assist, we ended up using something quite  similar to this.
I'm refactoring a portion of an app that was originally all in python, but
now some functions were required to use the DB stored procedures instead for
compatibility, and they weren't designed to be used in Twisted-fashion! On
to the next interesting Twisted problem.....
Ken

@inlineCallbacks must decorate only generator functions.
>
> Since 'yield' doesn't appear anywhere in the body of round_val (or, for
> that matter, round_per) this code will break in other ways.  Allen Short's
> suggestion will fix your code because it added a 'yield', but you need to be
> aware of this issue in case there are other such functions in the future
> that don't actually handle any Deferreds.
>
> Also, inlineCallbacks adds some overhead, and really should only be used
> when the resulting code is easier to read.  Personally, I think a simpler
> definition of round_val would be simply
>
>    def round_val(id, value, rule):
>        """
>        Return first element of round_value_and_percent
>        """
>         return round_value_and_percent(id, value, 0, rule).addCallback(
>            lambda valueAndPercent: valueAndPercent[0]
>        )
>
> no @inlineCallbacks required.
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20100716/82d50c8b/attachment-0001.htm 


More information about the Twisted-Python mailing list