Does Python learn?

Not a serious question. However sometimes it seems it does.

I ran an existing working program that among other things, generates fake dates. It uses try/except logic to make sure the date is valid, because I'm lazy and decided to let Python do some of the work. So, if I give the python date function date() an invalid date it will give an error. All of a sudden it starts throwing ValueError errors. Which obviously I sometimes expect...hence the except. Like I said this was an existing working program that I've used to generate many millions of records. Sure if I generate 10 random dates there's a chance that every date is valid. But not very likely generating millions. I need to buy a lottery ticket on the day where I can generate a million valid random dates!

Side question. If I do some of the work will my program run faster?

Anyways I isolated (via cut & paste) the try/except logic from the main program. Sure enough sometimes I would get the ValueError. I placed various prints to help me see what was going on. Then all of a sudden I wasn't getting any errors. Almost as if, I say tongue in cheek, Python said Oh now I see what you are doing . So you might say with all my adding this and adding that I inadvertently fixed the problem. Seems likely.

However when I went back to the original program that mysteriously seemed to stop working...it now works!?!?! WTH?

2020-06-11 16:40:26
Index