1

I am using pyCurl with the following line to call a function with the data of the connection:

conn.setopt(pycurl.WRITEFUNCTION, on_receive)

Is there anyway I can pass more parameters to on_receive function, such as:

conn.setopt(pycurl.WRITEFUNCTION, on_receive, parameter_1, parameter_2) 

Thanks,

Joel

Joel
  • 5,949
  • 12
  • 42
  • 58

1 Answers1

3

The only straight-forward way I know would be to have a separate springboard function to call your actual function with the additional parameters. A lambda function or function pointer in other words, if the parameters are ok to be constant.

connn.setopt(pycurl.WRITEFUNCTION, lambda data: real_impl(data, param1, param2))
Per Fagrell
  • 835
  • 7
  • 15
  • 4
    Do `lambda data, p1=param1, p2=param2: real_impl(data, p1, p2))` to avoid bugs like: http://stackoverflow.com/q/139819/4279 – jfs Dec 06 '10 at 11:26