Re: [Tutor] group txt files by month

2012-09-08 Thread Mark Lawrence

On 08/09/2012 05:47, questions anon wrote:

Hello All, it has been a few months since I have used this and I have only
just realised I am having problems with leap years. each time I get to
February of a leap year my program stops, therefore I have attributed it to
my code not accounting for leap years. Is there a simple way to fix my code
(below) to account for leap years?

Thanks


stop_month = datetime(2011, 12, 31)
month = datetime(2011, 01, 01)

while month < stop_month:
 accumulate_month(month.year, month.month)
 month += timedelta(days=32)
 month = month.replace(day=01)



How about this as an alternative, noting that dateutil is a third party 
library and not in the standard library?


from dateutil.relativedelta import relativedelta as rd
def incrMonth(date):
return date + rd(months = 1)

The same pattern can be used for days, years etc.

--
Cheers.

Mark Lawrence.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] group txt files by month

2012-09-08 Thread questions anon
hmmm thank you, I obviously need to put some more thought in first.
Thanks for the responses.

On Sat, Sep 8, 2012 at 4:03 PM, Peter Otten <__pete...@web.de> wrote:

> questions anon wrote:
>
> > Hello All, it has been a few months since I have used this and I have
> only
> > just realised I am having problems with leap years. each time I get to
> > February of a leap year my program stops,
>
> Does it throw an exception (if so, post the traceback) or does it just
> terminate?
>
> > therefore I have attributed it
> > to my code not accounting for leap years. Is there a simple way to fix my
> > code (below) to account for leap years?
>
>
> > stop_month = datetime(2011, 12, 31)
> > month = datetime(2011, 01, 01)
>
> Hm, 2011 is not a leap year.
>
> > while month < stop_month:
> > accumulate_month(month.year, month.month)
> > month += timedelta(days=32)
> > month = month.replace(day=01)
>
> Anyway, this piece of code should work the same for leap years and non-leap
> years. The problem must be in the code you are not posting (or in your
> data).
>
> PS:
>
> > month = datetime(2011, 01, 01)
>
> Stylistic note: numbers starting with 0 are interpreted as octals. It
> doesn't matter here, but don't get into the habit:
>
> >>> 010 == 10
> False
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] I need Help

2012-09-08 Thread tayo rotimi
Hi,


I am a new beginner/learner of Python. My first challenge is that I am unable 
to install the Python IDLE after downloading it from Python website. When I hit 
on the 'run' button, i got the error message below:

"This installation package could not be opened. Contact the application vendor 
to verify that this a valid Window Installer Package."

Furthermore, I read from the 'python for absolute beginners' text book that I 
need to add some code to the end of path in my computer property. Could this 
really be the solution to my problem? If it is, then I don't know how get such 
code to add. 


I don't know what to do.

I use Windows 7 OS.

Could someone help provide me a guide?

Regards to all.

Tayo.      
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need Help

2012-09-08 Thread Steven D'Aprano

Hi Tavo,

My responses are interleaved between your comments, shown with > markers.


On 09/09/12 02:24, tayo rotimi wrote:

Hi,


I am a new beginner/learner of Python.


Welcome and good luck!


My first challenge is that I am unable to install the Python IDLE after
downloading it from Python website. When I hit on the 'run' button, i
got the error message below:

"This installation package could not be opened. Contact the application
vendor to verify that this a valid Window Installer Package."


What are you downloading? As far as I can see, there is no installer for
IDLE on the Python website. IDLE comes automatically with the rest of the
Python installer. Please tell us:

* what page you go to on the Python website to find this installer
* which installer link you click on
* the exact name of the installer file you download
* whether your version of Windows is 32-bit or 64-bit



Furthermore, I read from the 'python for absolute beginners' text book
that I need to add some code to the end of path in my computer property.


Really? Does it say what code to add, or will any old code do?

Without knowing exactly what the book says, and the context, I have no
idea what that means.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need Help

2012-09-08 Thread Matthew Ngaha
this is the same book i bought a few months ago to get me started. the
instructions i remember where clear for windows. if there is a problem
with the download files on the site, the author has the files on his
own site also:

http://www.programgames.com/page4.html

save or run the file, once installed go to your start menu, choose All
Programs, choose Python 3.1, then choose IDLE(Python GUI)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor