[Chicago] Bokeh methods as arguments

Robare, Phillip (TEKSystems) proba at allstate.com
Fri Jun 24 12:46:15 EDT 2016


Just ran across another way you could do this.  In the operator module there is 
operator.methodcaller(name[, args...])
Return a callable object that calls the method name on its operand. If additional arguments and/or keyword arguments are given, they will be given to the method as well. For example:
After f = methodcaller('name'), the call f(b) returns b.name().
After f = methodcaller('name', 'foo', bar=1), the call f(b) returns b.name('foo', bar=1).

So you could have square = methodcaller('square', ...params... ) and then a call to b.square becomes square(b).


Phil Robare


-----Original Message-----
From: Chicago [mailto:chicago-bounces+proba=allstate.com at python.org] On Behalf Of Robin Fishbein via Chicago
Sent: Thursday, June 23, 2016 4:18 PM
To: Aaron Elmquist <elmq0022 at umn.edu>
Cc: Robin Fishbein <robinfishbein at yahoo.com>; The Chicago Python Users Group <chicago at python.org>
Subject: Re: [Chicago] Bokeh methods as arguments

Thanks Brian, Aaron, Phil!
I tested these approaches, and each one of them worked. I imagine I'll probably use Brian's approach, defining a function, because it decouples the list of shape method names from the Figure instance's symbol.

I had tried creating my own class based on Figure, but Jupyter Notebook didn't want to display an object not specifically of the Figure class. I also got errors when trying to use add my own method to a Figure instance with setattr.

Bokeh's scatter marker methods where the marker has no interior (x, asterisk, and one other I can't think of) conveniently ignore fill_* keyword arguments. Probably didn't have my use case in mind, rather just if someone decides to change from 'circle' to 'x' they can do so without having to know to remove the fill_color.

-Robin

_______________________________________________
Chicago mailing list
Chicago at python.org
https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_chicago&d=CwICAg&c=gtIjdLs6LnStUpy9cTOW9w&r=VXIryE9UwJGlNMLzgMzDT4_t2NMrZf6alSphHwSEwC0&m=m7nod_-xUn1tdNT3sqrwgNzZrdZ4GRUnza7kh2c9IXE&s=zAmSvblD7iD6nKw-qZl_DM3Zs2MaNKvYRG_i9fUTWcU&e= 


More information about the Chicago mailing list