On Wed, 18 Aug 2010 23:18:06 +1200
Lawrence D'Oliveiro <l...@geek-central.gen.new_zealand> wrote:
> Might I suggest (guessing at the argument keywords here) :
> 
>     self.expiration_date = translate_date \
>       (
>         TheText = find(response, 'MPNExpirationDate').text,
>         ToFormat ='%Y-%m-%d',
>         FromFormat ='%m%d%Y'
>       )

I sometimes use a backslash continuation but it always feels like a
failure to me.  It's an irrational reaction and I'm not sure why I feel
like that.  However, if you are going to do it in order to line up the
parenthese I would prefer this style.

     self.expiration_date = translate_date \
     (
         TheText = find(response, 'MPNExpirationDate').text,
         ToFormat ='%Y-%m-%d',
         FromFormat ='%m%d%Y'
     )

This way you can see not only the block structure at a glance but also
the block starter that it is part of.

> 
> Presumably FromFormat should be localizable, rather than hard-coded.
> 
> See, that’s the kind of thing you notice when you think about the code in 
> this way.

The other thing that jumps out at me is having the input format
different than the output format.  In any case you need a better date
input function.  There's no reason in this day and age to force users
into a particular input form.  You should think about creating a
utility function that converts any date that is unambiguous.  My
scripts generally accept all of the following.

Sep 1 2010
september 1, 2010
2010-9-1 (I have never seen "Y/D/M" format)
2010/9/1
2010 9 1
12/25/2010
25/12/2010
2010/12/25

It fails on the following.

sep 31 2010 (impossible)
2010/25/12 (impossible - Y/D/M never happens)
9/1/2010 (ambiguous - there is no consistiency when year is last field)
foo (not a date)

-- 
D'Arcy J.M. Cain <da...@druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to