Pull Last 3 Months

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Oct 18 06:25:48 CEST 2007


En Wed, 17 Oct 2007 21:47:50 -0300, Tim Chase  
<python.list at tim.thechases.com> escribió:

> In the event that you need them in whatever your locale is, you
> can use the '%b' formatting to produce them:

I prefer the calendar module in that case:

py> import locale
py> locale.setlocale(locale.LC_ALL, '')
'Spanish_Argentina.1252'
py>
py> import calendar
py> calendar.month_abbr[12]
'Dic'
py> def prev_months(since, howmany):
...   return [calendar.month_abbr[(since.month-i-2) % 12 + 1] for i in  
range(how
many)]
...
py> import datetime
py> prev_months(datetime.datetime(2005,2,10), 4)
['Ene', 'Dic', 'Nov', 'Oct']
py> prev_months(datetime.datetime(2005,10,17), 3)
['Sep', 'Ago', 'Jul']

-- 
Gabriel Genellina




More information about the Python-list mailing list