Re: Find day of week from month and year

2005-09-14 Thread John Machin
Terry Reedy wrote: >>Laguna wrote: >> >>>I want to find the expiration date of stock options (3rd Friday of the >>>month) for an any give month and year. > > >>From year and month (and day=1) get the day of the week (n in [0,6]) of the > first of the month using some version of the the standard

Re: Find day of week from month and year

2005-09-14 Thread Terry Reedy
> Laguna wrote: >> I want to find the expiration date of stock options (3rd Friday of the >> month) for an any give month and year. >From year and month (and day=1) get the day of the week (n in [0,6]) of the first of the month using some version of the the standard formula (see below) and look

Re: Find day of week from month and year

2005-09-14 Thread tryit
>>> import calendar >>> [y[4] for y in calendar.monthcalendar(2005, 9) if y[4]!=0][2] 16 >>> [y[4] for y in calendar.monthcalendar(2003, 6) if y[4]!=0][2] 20 >>> [y[4] for y in calendar.monthcalendar(2006, 2) if y[4]!=0][2] 17 -- http://mail.python.org/mailman/listinfo/python-list

Re: Find day of week from month and year

2005-09-14 Thread tryit
Laguna wrote: > Hi Gurus, > > I want to find the expiration date of stock options (3rd Friday of the > month) for an any give month and year. I have tried a few tricks with > the functions provided by the built-in module time, but the problem was > that the 9 element tuple need to be populated corr

Re: Find day of week from month and year

2005-09-14 Thread tryit
Laguna wrote: > Hi Gurus, > > I want to find the expiration date of stock options (3rd Friday of the > month) for an any give month and year. I have tried a few tricks with > the functions provided by the built-in module time, but the problem was > that the 9 element tuple need to be populated cor

Re: Find day of week from month and year

2005-09-03 Thread Jorgen Grahn
On Fri, 02 Sep 2005 20:53:44 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: > Carsten Haese wrote: >> On Fri, 2005-09-02 at 16:46, Laguna wrote: >>>def expiration(year, month): >>> weekday = calendar.weekday(year, month, 1) >>> table = [19, 18, 17, 16, 15, 21, 20] >>> return table[weekd

Re: Find day of week from month and year

2005-09-03 Thread Peter Hansen
Paul Rubin wrote: > Peter Hansen <[EMAIL PROTECTED]> writes: > >>(And, if I were "optimizing", I would of course dispense with the >>dynamic creation of the static table upon every execution of >>expiration(), and move it outside the function.) > > Replacing it with a tuple might be enough for th

Re: Find day of week from month and year

2005-09-03 Thread Paul McGuire
Donn, You didn't look closely enough at those results. The OP's point was that he did not know how to set all the tuple values correctly. Here's a clearer example, I think: import time print time.asctime((2005,9,1,0,0,0,0,0,0)) print time.asctime((2005,9,1,0,0,0,1,0,0)) print time.asctime((2005

Re: Find day of week from month and year

2005-09-02 Thread John Machin
Peter Hansen wrote: > Carsten Haese wrote: > >> On Fri, 2005-09-02 at 16:46, Laguna wrote: >> >>> def expiration(year, month): >>> weekday = calendar.weekday(year, month, 1) >>> table = [19, 18, 17, 16, 15, 21, 20] >>> return table[weekday] >>> >> This, of course, can be "optimized" in

Re: Find day of week from month and year

2005-09-02 Thread Paul Rubin
Peter Hansen <[EMAIL PROTECTED]> writes: > (And, if I were "optimizing", I would of course dispense with the > dynamic creation of the static table upon every execution of > expiration(), and move it outside the function.) Replacing it with a tuple might be enough for that. -- http://mail.python.

Re: Find day of week from month and year

2005-09-02 Thread Peter Hansen
Carsten Haese wrote: > On Fri, 2005-09-02 at 16:46, Laguna wrote: >>def expiration(year, month): >> weekday = calendar.weekday(year, month, 1) >> table = [19, 18, 17, 16, 15, 21, 20] >> return table[weekday] >> > This, of course, can be "optimized" into > > def expiration(year, mont

Re: Find day of week from month and year

2005-09-02 Thread Laguna
Hey Donn, I don't mean to offend anyone here. I was just saying that the other solution is better suited for my problem. I truly appreciate your analysis and suggestions. BTW, I am not a programmer :( and I like the simplest solution whenever possible. Cheers, L -- http://mail.python.org/mailm

Re: Find day of week from month and year

2005-09-02 Thread Donn Cave
In article <[EMAIL PROTECTED]>, "Laguna" <[EMAIL PROTECTED]> wrote: > > What do you mean by, "the 9 element tuple need to be populated > > correctly"? Do you need someone to tell you what values it > > needs? What happens if you use (2005, 9, 1, 0, 0, 0, 0, 0, 0), > > for example? If you make

Re: Find day of week from month and year

2005-09-02 Thread Laguna
Thanks for the "hint" :) I may use your solution if this becomes my bottleneck! I try to get away from Perl-ish syntax though. Best, L -- http://mail.python.org/mailman/listinfo/python-list

Re: Find day of week from month and year

2005-09-02 Thread Carsten Haese
On Fri, 2005-09-02 at 16:46, Laguna wrote: > Paul, > > Thanks for the suggestion on calendar module. Here is my solution and > it works: > > def expiration(year, month): > weekday = calendar.weekday(year, month, 1) > table = [19, 18, 17, 16, 15, 21, 20] > return table[weekday] >

Re: Find day of week from month and year

2005-09-02 Thread Laguna
Paul, Thanks for the suggestion on calendar module. Here is my solution and it works: def expiration(year, month): weekday = calendar.weekday(year, month, 1) table = [19, 18, 17, 16, 15, 21, 20] return table[weekday] Cheers, Laguna -- http://mail.python.org/mailman/list

Re: Find day of week from month and year

2005-09-02 Thread Laguna
> What do you mean by, "the 9 element tuple need to be populated > correctly"? Do you need someone to tell you what values it > needs? What happens if you use (2005, 9, 1, 0, 0, 0, 0, 0, 0), > for example? If you make this tuple with localtime or gmtime, > do you know what the 7th (tm[6]) elemen

Re: Find day of week from month and year

2005-09-02 Thread Donn Cave
In article <[EMAIL PROTECTED]>, "Laguna" <[EMAIL PROTECTED]> wrote: > I want to find the expiration date of stock options (3rd Friday of the > month) for an any give month and year. I have tried a few tricks with > the functions provided by the built-in module time, but the problem was > that the

Re: Find day of week from month and year

2005-09-02 Thread Robert Kern
Laguna wrote: > Hi Gurus, > > I want to find the expiration date of stock options (3rd Friday of the > month) for an any give month and year. I have tried a few tricks with > the functions provided by the built-in module time, but the problem was > that the 9 element tuple need to be populated cor

Re: Find day of week from month and year

2005-09-02 Thread Paul Rubin
"Laguna" <[EMAIL PROTECTED]> writes: > I want to find the expiration date of stock options (3rd Friday of the > month) for an any give month and year. I have tried a few tricks with > the functions provided by the built-in module time, but the problem was > that the 9 element tuple need to be popul

Find day of week from month and year

2005-09-02 Thread Laguna
Hi Gurus, I want to find the expiration date of stock options (3rd Friday of the month) for an any give month and year. I have tried a few tricks with the functions provided by the built-in module time, but the problem was that the 9 element tuple need to be populated correctly. Can anyone help me