Is this pythonic?

Jason Scheirer jason.scheirer at gmail.com
Thu Dec 18 19:51:08 CET 2008


On Dec 18, 8:45 am, prueba... at latinmail.com wrote:
> On Dec 18, 11:08 am, ipyt... at gmail.com wrote:
>
> > x.validate_output(x.find_text(x.match_filename
> > (x.determine_filename_pattern(datetime.datetime.now()))))
>
> > Is it even good programming form?
>
> Lisp and Scheme programmers love that style. You can tell by the
> number of parentheses :-). In Python people usually use an
> intermediate variable to break things up a bit but the amount of
> acceptable nesting is a matter of personal style.

I'd say it's fine but breaking up the statement once or twice is a
good idea just because if one of the function calls in this nested
thing throws an exception, a smaller statement with fewer calls makes
for a far more readable traceback. And I hope that this whole
statement all lives inside of a method in the same x class, or is a
higher-level class that makes use of this behavior? If not, you may
want to consider doing so.

class X(object):
  @property
  def todays_filepattern(self):
      return self.match_filename(
              self.determine_filename_pattern(
                   datetime.datetime.now()))
  def validate_todays_files(self):
     return self.validate_output(self.find_text
(self.todays_filepattern))



More information about the Python-list mailing list