[CentralOH] Ugliest Line of Python Ever?

Jon Miller jonebird at gmail.com
Thu Oct 28 04:30:58 CEST 2010


Much cleaner!

Thanks.
Jon Miller

On Wed, Oct 27, 2010 at 9:13 PM, Chris Chandler
<chris at developingchris.com> wrote:
> what about?
>
> from datetime import datetime,timedelta,time,date
> print datetime.combine(game.gametime.date() - timedelta(days=1), time(12,0))
>
> Then at least its less,hand wavy with the formatting.
>
> Thanks,
> Chris Chandler
> 352-871-0712
>
>
> On Wed, Oct 27, 2010 at 8:20 PM, Jon Miller <jonebird at gmail.com> wrote:
>>
>> I think I just typed the ugliest line of python code in iPython
>> ever?... and I don't mind sharing it since you might get a chuckle out
>> of it:
>>
>> In [18]: datetime.datetime(*[ int(x) for x in (game.gametime -
>> datetime.timedelta(hours=24)).strftime('%Y %m %d 12 0').split()])
>> Out[18]: datetime.datetime(2010, 10, 27, 12, 0)
>>
>> I was trying to create a datetime object for twelve noon on the
>> previous day before the game.
>> (game is the DB object and game.gametime should be pretty obvious)
>>
>> I'm going to split it up for readability but I'm still don't have a
>> better way to do this.
>>
>> -- Jon Miller
>> _______________________________________________
>> CentralOH mailing list
>> CentralOH at python.org
>> http://mail.python.org/mailman/listinfo/centraloh
>
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
>
>


More information about the CentralOH mailing list