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

Ken MacDonald drken567 at gmail.com
Thu Jul 15 16:32:33 EDT 2010


I have a function and two convenience functions, like this:

    @defer.inlineCallbacks
    def round_value_and_percent(id, value, percent):
            daily = 1.

            params = dict(nutidin=id, valuein=value, dvin=daily)
            query = "ROUND_NUT_DV"
            q_result = yield named_query_param(ctx, "nut", query, params)
// db query
            rounded = {}
            rounded["value"] = q_result[0][0]
            rounded["percent"] = q_result[0][1]
            defer.returnValue((rounded['value'], rounded['percent']))

    @defer.inlineCallbacks
    def round_val(id, value, rule):
        """
        Return first element of round_value_and_percent
        """
        defer.returnValue(round_value_and_percent(id, value, 0, rule)[0])


    @defer.inlineCallbacks
    def round_per(id, percent, rule):
        """
        Return second element of round_value_and_percent.
        """
        defer.returnValue(round_value_and_percent(id, 0, percent, rule)[1])

When I do:
result = yield round_val(1, 2, 3)

I get this: Deferred instance has no attribute '__getitem__'

Clues appreciated!
Ken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20100715/fd171361/attachment.htm 


More information about the Twisted-Python mailing list