Method Chaining
Jussi Piitulainen
jussi.piitulainen at helsinki.fi
Fri Jun 17 04:45:51 EDT 2016
Lawrence D’Oliveiro writes:
> On Friday, June 17, 2016 at 8:13:50 PM UTC+12, Ned Batchelder wrote:
>> But the unchained version is more explicit, and avoids
>> the awkward parenthesis.
>
> What if it had been
>
> the_context.move_to((p1 + p2a) / 2)
> the_context.line_to(p1 + (p2 - p1) * frac)
> the_context.line_to((p1 + p1a) / 2)
> the_context.stroke()
> the_context.move_to((p2 + p2a) / 2)
> the_context.line_to(p2 + (p1 - p2) * frac)
> the_context.line_to((p2 + p1a) / 2)
> the_context.stroke()
>
> ?
g = the_context
g.move_to((p1 + p2a) / 2)
g.line_to(p1 + (p2 - p1) * frac)
g.line_to((p1 + p1a) / 2)
g.stroke()
g.move_to((p2 + p2a) / 2)
g.line_to(p2 + (p1 - p2) * frac)
g.line_to((p2 + p1a) / 2)
g.stroke()
More information about the Python-list
mailing list