Would it make sense to define a fallback call method for PyObject values that tries to apply the PyObject as a python function?
> On Jul 19, 2015, at 7:42 AM, Avik Sengupta <[email protected]> wrote: > > Sometimes PyCall cannot infer that an object is callable, since so many in > python are (beyond simple functions). In such situations, the workaround is > to use the "pycall" function in julia directly. See the invocations below... > > julia> urllib2.Request("http://google.com") > > ERROR: type: apply: expected Function, got PyObject > > > > julia> urllib2.urlopen("http://google.com") > > PyObject <addinfourl at 4660350848 whose fp = <socket._fileobject object at > 0x1168f1ed0>> > > > > julia> req = pycall(urllib2.Request, PyAny, "http://google.com") > > PyObject <urllib2.Request instance at 0x115c74d40> > > > > julia> f=urllib2.urlopen(req) > > PyObject <addinfourl at 4660402584 whose fp = <socket._fileobject object at > 0x1168f76d0>> > > > > julia> f[:read](100) > > "<!doctype html><html itemscope=\"\" itemtype=\"http://schema.org/WebPage\" > lang=\"en-GB\"><head><meta cont" > > >> On Sunday, 19 July 2015 03:15:28 UTC+1, Dejan Miljkovic wrote: >> What would be the right way to execute urllib2 call in julia >> >> using PyCall >> @pyimport urllib2 as urllib2 >> request = urllib2.Request(url, json_payload, "{'Content-Type': >> 'application/json'}") >> >> type: apply: expected Function, got PyObject >> while loading In[29], in expression starting on line 1 >> >> >> Thanks, >> >> Dejan
