Project

General

Profile

Python module usage

Added by Ugur Cayoglu over 7 years ago

Hi there,

I wrote a small python module for easier handling of cdo operations and
I would like to hear from the community what they think about it.

You can find the repository at [0]. The basic idea is to use
it like method chaining in javascript [1].

[0] https://github.com/ucyo/cdochain
[1] https://schier.co/blog/2013/11/14/method-chaining-in-javascript.html

Thanks and I hope it helps during daily work.

CU
UC


Replies (2)

RE: Python module usage - Added by Ralf Mueller over 7 years ago

Hi!

Method chaining is pretty normal, when it comes to OO languages like ruby, python, C++ or so. I could have implemented this in the cdo-bindings (no matter if its ruby or python) by returning the object (self) at the end of each operator call. In that case you get chaining for free.

There are reasons, why I didn't

  • User should have most easy access to output files (so I used this as the default return value)
  • Operator chains have to be called at once to get the internal parallelism of CDO running - otherwise is is creating additional temporal files. Here the built-in chaining (above) would not work. You seem to be aware of this (https://github.com/ucyo/cdochain/blob/master/cdochain/chaining.py#L70), but TBH I did not fully understand yet, if it's doing the right thing. I will take a closer look and add some tests to see what it really does.

Syntactically the chain looks brilliant!

thx for the effort
ralf

RE: Python module usage - Added by Ugur Cayoglu over 7 years ago

Hi Ralf,

thank you for your feedback! :)

I don't know about Ruby, but in Python - just returning 'self' - won't work. The reason for this is explained in [0].

[0] http://derrickgilland.com/posts/introduction-to-generative-classes-in-python/

The final 'execute' command is creating the appropriate one liner and sends the command to cdo.Cdo()
I didn't refactor the code yet, but will be doing that soon :)

    (1-2/2)