From my understanding of Pythonic's coding style (and in particular PEP20), the code should be simple and readable. With that in mind, is the cascading method considered Pythonic?
For example, let's say we have a Cascade class:
class Cascade(object): def __init__(self, pythonic): self.question = 'Is this Pythonic?' self.answer = pythonic def copy(self): import copy return copy.deepcopy(self) def is_pythonic(self): return self.answer
Then what is better:
>>> cas = Cascade(False) >>> cas.copy().is_pythonic() False
Or else:
>>> cas1 = Cascade(False) >>> cas2 = cas1.copy() >>> cas2.is_pythonic() False
The first option, in my opinion, is more readable, since my eyes run from left to right - almost akin to reading a book, while the second contains one simple statement in a line (which, admittedly, is also well read).
EDIT
Following the helpful comments by Haleemur Ali , Lutz Horn and claust , I would like to rephrase the question in the broader "When should I use the cascading method in Python?"
source share